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,200
|
muesli/beehive
|
beehive.go
|
loadConfig
|
func loadConfig() Config {
config := Config{}
j, err := ioutil.ReadFile(configFile)
if err == nil {
err = json.Unmarshal(j, &config)
if err != nil {
log.Fatal("Error parsing config file: ", err)
}
}
return config
}
|
go
|
func loadConfig() Config {
config := Config{}
j, err := ioutil.ReadFile(configFile)
if err == nil {
err = json.Unmarshal(j, &config)
if err != nil {
log.Fatal("Error parsing config file: ", err)
}
}
return config
}
|
[
"func",
"loadConfig",
"(",
")",
"Config",
"{",
"config",
":=",
"Config",
"{",
"}",
"\n\n",
"j",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"configFile",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"j",
",",
"&",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"config",
"\n",
"}"
] |
// Loads chains from config
|
[
"Loads",
"chains",
"from",
"config"
] |
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
|
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/beehive.go#L58-L70
|
21,201
|
muesli/beehive
|
beehive.go
|
saveConfig
|
func saveConfig(c Config) {
j, err := json.MarshalIndent(c, "", " ")
if err == nil {
err = ioutil.WriteFile(configFile, j, 0644)
}
if err != nil {
log.Fatal(err)
}
}
|
go
|
func saveConfig(c Config) {
j, err := json.MarshalIndent(c, "", " ")
if err == nil {
err = ioutil.WriteFile(configFile, j, 0644)
}
if err != nil {
log.Fatal(err)
}
}
|
[
"func",
"saveConfig",
"(",
"c",
"Config",
")",
"{",
"j",
",",
"err",
":=",
"json",
".",
"MarshalIndent",
"(",
"c",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"err",
"=",
"ioutil",
".",
"WriteFile",
"(",
"configFile",
",",
"j",
",",
"0644",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Fatal",
"(",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// Saves chains to config
|
[
"Saves",
"chains",
"to",
"config"
] |
4bfd4852e0b4bdcbc711323775cc7144ccd81b7e
|
https://github.com/muesli/beehive/blob/4bfd4852e0b4bdcbc711323775cc7144ccd81b7e/beehive.go#L73-L82
|
21,202
|
stretchr/testify
|
mock/mock.go
|
Maybe
|
func (c *Call) Maybe() *Call {
c.lock()
defer c.unlock()
c.optional = true
return c
}
|
go
|
func (c *Call) Maybe() *Call {
c.lock()
defer c.unlock()
c.optional = true
return c
}
|
[
"func",
"(",
"c",
"*",
"Call",
")",
"Maybe",
"(",
")",
"*",
"Call",
"{",
"c",
".",
"lock",
"(",
")",
"\n",
"defer",
"c",
".",
"unlock",
"(",
")",
"\n",
"c",
".",
"optional",
"=",
"true",
"\n",
"return",
"c",
"\n",
"}"
] |
// Maybe allows the method call to be optional. Not calling an optional method
// will not cause an error while asserting expectations
|
[
"Maybe",
"allows",
"the",
"method",
"call",
"to",
"be",
"optional",
".",
"Not",
"calling",
"an",
"optional",
"method",
"will",
"not",
"cause",
"an",
"error",
"while",
"asserting",
"expectations"
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L166-L171
|
21,203
|
stretchr/testify
|
mock/mock.go
|
fail
|
func (m *Mock) fail(format string, args ...interface{}) {
m.mutex.Lock()
defer m.mutex.Unlock()
if m.test == nil {
panic(fmt.Sprintf(format, args...))
}
m.test.Errorf(format, args...)
m.test.FailNow()
}
|
go
|
func (m *Mock) fail(format string, args ...interface{}) {
m.mutex.Lock()
defer m.mutex.Unlock()
if m.test == nil {
panic(fmt.Sprintf(format, args...))
}
m.test.Errorf(format, args...)
m.test.FailNow()
}
|
[
"func",
"(",
"m",
"*",
"Mock",
")",
"fail",
"(",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"m",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"m",
".",
"test",
"==",
"nil",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"format",
",",
"args",
"...",
")",
")",
"\n",
"}",
"\n",
"m",
".",
"test",
".",
"Errorf",
"(",
"format",
",",
"args",
"...",
")",
"\n",
"m",
".",
"test",
".",
"FailNow",
"(",
")",
"\n",
"}"
] |
// fail fails the current test with the given formatted format and args.
// In case that a test was defined, it uses the test APIs for failing a test,
// otherwise it uses panic.
|
[
"fail",
"fails",
"the",
"current",
"test",
"with",
"the",
"given",
"formatted",
"format",
"and",
"args",
".",
"In",
"case",
"that",
"a",
"test",
"was",
"defined",
"it",
"uses",
"the",
"test",
"APIs",
"for",
"failing",
"a",
"test",
"otherwise",
"it",
"uses",
"panic",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L231-L240
|
21,204
|
stretchr/testify
|
mock/mock.go
|
AssertExpectationsForObjects
|
func AssertExpectationsForObjects(t TestingT, testObjects ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
for _, obj := range testObjects {
if m, ok := obj.(Mock); ok {
t.Logf("Deprecated mock.AssertExpectationsForObjects(myMock.Mock) use mock.AssertExpectationsForObjects(myMock)")
obj = &m
}
m := obj.(assertExpectationser)
if !m.AssertExpectations(t) {
t.Logf("Expectations didn't match for Mock: %+v", reflect.TypeOf(m))
return false
}
}
return true
}
|
go
|
func AssertExpectationsForObjects(t TestingT, testObjects ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
for _, obj := range testObjects {
if m, ok := obj.(Mock); ok {
t.Logf("Deprecated mock.AssertExpectationsForObjects(myMock.Mock) use mock.AssertExpectationsForObjects(myMock)")
obj = &m
}
m := obj.(assertExpectationser)
if !m.AssertExpectations(t) {
t.Logf("Expectations didn't match for Mock: %+v", reflect.TypeOf(m))
return false
}
}
return true
}
|
[
"func",
"AssertExpectationsForObjects",
"(",
"t",
"TestingT",
",",
"testObjects",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"obj",
":=",
"range",
"testObjects",
"{",
"if",
"m",
",",
"ok",
":=",
"obj",
".",
"(",
"Mock",
")",
";",
"ok",
"{",
"t",
".",
"Logf",
"(",
"\"",
"\"",
")",
"\n",
"obj",
"=",
"&",
"m",
"\n",
"}",
"\n",
"m",
":=",
"obj",
".",
"(",
"assertExpectationser",
")",
"\n",
"if",
"!",
"m",
".",
"AssertExpectations",
"(",
"t",
")",
"{",
"t",
".",
"Logf",
"(",
"\"",
"\"",
",",
"reflect",
".",
"TypeOf",
"(",
"m",
")",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// AssertExpectationsForObjects asserts that everything specified with On and Return
// of the specified objects was in fact called as expected.
//
// Calls may have occurred in any order.
|
[
"AssertExpectationsForObjects",
"asserts",
"that",
"everything",
"specified",
"with",
"On",
"and",
"Return",
"of",
"the",
"specified",
"objects",
"was",
"in",
"fact",
"called",
"as",
"expected",
".",
"Calls",
"may",
"have",
"occurred",
"in",
"any",
"order",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L414-L430
|
21,205
|
stretchr/testify
|
mock/mock.go
|
AssertExpectations
|
func (m *Mock) AssertExpectations(t TestingT) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
m.mutex.Lock()
defer m.mutex.Unlock()
var somethingMissing bool
var failedExpectations int
// iterate through each expectation
expectedCalls := m.expectedCalls()
for _, expectedCall := range expectedCalls {
if !expectedCall.optional && !m.methodWasCalled(expectedCall.Method, expectedCall.Arguments) && expectedCall.totalCalls == 0 {
somethingMissing = true
failedExpectations++
t.Logf("FAIL:\t%s(%s)\n\t\tat: %s", expectedCall.Method, expectedCall.Arguments.String(), expectedCall.callerInfo)
} else {
if expectedCall.Repeatability > 0 {
somethingMissing = true
failedExpectations++
t.Logf("FAIL:\t%s(%s)\n\t\tat: %s", expectedCall.Method, expectedCall.Arguments.String(), expectedCall.callerInfo)
} else {
t.Logf("PASS:\t%s(%s)", expectedCall.Method, expectedCall.Arguments.String())
}
}
}
if somethingMissing {
t.Errorf("FAIL: %d out of %d expectation(s) were met.\n\tThe code you are testing needs to make %d more call(s).\n\tat: %s", len(expectedCalls)-failedExpectations, len(expectedCalls), failedExpectations, assert.CallerInfo())
}
return !somethingMissing
}
|
go
|
func (m *Mock) AssertExpectations(t TestingT) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
m.mutex.Lock()
defer m.mutex.Unlock()
var somethingMissing bool
var failedExpectations int
// iterate through each expectation
expectedCalls := m.expectedCalls()
for _, expectedCall := range expectedCalls {
if !expectedCall.optional && !m.methodWasCalled(expectedCall.Method, expectedCall.Arguments) && expectedCall.totalCalls == 0 {
somethingMissing = true
failedExpectations++
t.Logf("FAIL:\t%s(%s)\n\t\tat: %s", expectedCall.Method, expectedCall.Arguments.String(), expectedCall.callerInfo)
} else {
if expectedCall.Repeatability > 0 {
somethingMissing = true
failedExpectations++
t.Logf("FAIL:\t%s(%s)\n\t\tat: %s", expectedCall.Method, expectedCall.Arguments.String(), expectedCall.callerInfo)
} else {
t.Logf("PASS:\t%s(%s)", expectedCall.Method, expectedCall.Arguments.String())
}
}
}
if somethingMissing {
t.Errorf("FAIL: %d out of %d expectation(s) were met.\n\tThe code you are testing needs to make %d more call(s).\n\tat: %s", len(expectedCalls)-failedExpectations, len(expectedCalls), failedExpectations, assert.CallerInfo())
}
return !somethingMissing
}
|
[
"func",
"(",
"m",
"*",
"Mock",
")",
"AssertExpectations",
"(",
"t",
"TestingT",
")",
"bool",
"{",
"if",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n",
"m",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"var",
"somethingMissing",
"bool",
"\n",
"var",
"failedExpectations",
"int",
"\n\n",
"// iterate through each expectation",
"expectedCalls",
":=",
"m",
".",
"expectedCalls",
"(",
")",
"\n",
"for",
"_",
",",
"expectedCall",
":=",
"range",
"expectedCalls",
"{",
"if",
"!",
"expectedCall",
".",
"optional",
"&&",
"!",
"m",
".",
"methodWasCalled",
"(",
"expectedCall",
".",
"Method",
",",
"expectedCall",
".",
"Arguments",
")",
"&&",
"expectedCall",
".",
"totalCalls",
"==",
"0",
"{",
"somethingMissing",
"=",
"true",
"\n",
"failedExpectations",
"++",
"\n",
"t",
".",
"Logf",
"(",
"\"",
"\\t",
"\\n",
"\\t",
"\\t",
"\"",
",",
"expectedCall",
".",
"Method",
",",
"expectedCall",
".",
"Arguments",
".",
"String",
"(",
")",
",",
"expectedCall",
".",
"callerInfo",
")",
"\n",
"}",
"else",
"{",
"if",
"expectedCall",
".",
"Repeatability",
">",
"0",
"{",
"somethingMissing",
"=",
"true",
"\n",
"failedExpectations",
"++",
"\n",
"t",
".",
"Logf",
"(",
"\"",
"\\t",
"\\n",
"\\t",
"\\t",
"\"",
",",
"expectedCall",
".",
"Method",
",",
"expectedCall",
".",
"Arguments",
".",
"String",
"(",
")",
",",
"expectedCall",
".",
"callerInfo",
")",
"\n",
"}",
"else",
"{",
"t",
".",
"Logf",
"(",
"\"",
"\\t",
"\"",
",",
"expectedCall",
".",
"Method",
",",
"expectedCall",
".",
"Arguments",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"somethingMissing",
"{",
"t",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\t",
"\\n",
"\\t",
"\"",
",",
"len",
"(",
"expectedCalls",
")",
"-",
"failedExpectations",
",",
"len",
"(",
"expectedCalls",
")",
",",
"failedExpectations",
",",
"assert",
".",
"CallerInfo",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"!",
"somethingMissing",
"\n",
"}"
] |
// AssertExpectations asserts that everything specified with On and Return was
// in fact called as expected. Calls may have occurred in any order.
|
[
"AssertExpectations",
"asserts",
"that",
"everything",
"specified",
"with",
"On",
"and",
"Return",
"was",
"in",
"fact",
"called",
"as",
"expected",
".",
"Calls",
"may",
"have",
"occurred",
"in",
"any",
"order",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L434-L466
|
21,206
|
stretchr/testify
|
mock/mock.go
|
AssertNumberOfCalls
|
func (m *Mock) AssertNumberOfCalls(t TestingT, methodName string, expectedCalls int) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
m.mutex.Lock()
defer m.mutex.Unlock()
var actualCalls int
for _, call := range m.calls() {
if call.Method == methodName {
actualCalls++
}
}
return assert.Equal(t, expectedCalls, actualCalls, fmt.Sprintf("Expected number of calls (%d) does not match the actual number of calls (%d).", expectedCalls, actualCalls))
}
|
go
|
func (m *Mock) AssertNumberOfCalls(t TestingT, methodName string, expectedCalls int) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
m.mutex.Lock()
defer m.mutex.Unlock()
var actualCalls int
for _, call := range m.calls() {
if call.Method == methodName {
actualCalls++
}
}
return assert.Equal(t, expectedCalls, actualCalls, fmt.Sprintf("Expected number of calls (%d) does not match the actual number of calls (%d).", expectedCalls, actualCalls))
}
|
[
"func",
"(",
"m",
"*",
"Mock",
")",
"AssertNumberOfCalls",
"(",
"t",
"TestingT",
",",
"methodName",
"string",
",",
"expectedCalls",
"int",
")",
"bool",
"{",
"if",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n",
"m",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"var",
"actualCalls",
"int",
"\n",
"for",
"_",
",",
"call",
":=",
"range",
"m",
".",
"calls",
"(",
")",
"{",
"if",
"call",
".",
"Method",
"==",
"methodName",
"{",
"actualCalls",
"++",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"assert",
".",
"Equal",
"(",
"t",
",",
"expectedCalls",
",",
"actualCalls",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"expectedCalls",
",",
"actualCalls",
")",
")",
"\n",
"}"
] |
// AssertNumberOfCalls asserts that the method was called expectedCalls times.
|
[
"AssertNumberOfCalls",
"asserts",
"that",
"the",
"method",
"was",
"called",
"expectedCalls",
"times",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L469-L482
|
21,207
|
stretchr/testify
|
mock/mock.go
|
AssertCalled
|
func (m *Mock) AssertCalled(t TestingT, methodName string, arguments ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
m.mutex.Lock()
defer m.mutex.Unlock()
if !m.methodWasCalled(methodName, arguments) {
var calledWithArgs []string
for _, call := range m.calls() {
calledWithArgs = append(calledWithArgs, fmt.Sprintf("%v", call.Arguments))
}
if len(calledWithArgs) == 0 {
return assert.Fail(t, "Should have called with given arguments",
fmt.Sprintf("Expected %q to have been called with:\n%v\nbut no actual calls happened", methodName, arguments))
}
return assert.Fail(t, "Should have called with given arguments",
fmt.Sprintf("Expected %q to have been called with:\n%v\nbut actual calls were:\n %v", methodName, arguments, strings.Join(calledWithArgs, "\n")))
}
return true
}
|
go
|
func (m *Mock) AssertCalled(t TestingT, methodName string, arguments ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
m.mutex.Lock()
defer m.mutex.Unlock()
if !m.methodWasCalled(methodName, arguments) {
var calledWithArgs []string
for _, call := range m.calls() {
calledWithArgs = append(calledWithArgs, fmt.Sprintf("%v", call.Arguments))
}
if len(calledWithArgs) == 0 {
return assert.Fail(t, "Should have called with given arguments",
fmt.Sprintf("Expected %q to have been called with:\n%v\nbut no actual calls happened", methodName, arguments))
}
return assert.Fail(t, "Should have called with given arguments",
fmt.Sprintf("Expected %q to have been called with:\n%v\nbut actual calls were:\n %v", methodName, arguments, strings.Join(calledWithArgs, "\n")))
}
return true
}
|
[
"func",
"(",
"m",
"*",
"Mock",
")",
"AssertCalled",
"(",
"t",
"TestingT",
",",
"methodName",
"string",
",",
"arguments",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n",
"m",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"m",
".",
"methodWasCalled",
"(",
"methodName",
",",
"arguments",
")",
"{",
"var",
"calledWithArgs",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"call",
":=",
"range",
"m",
".",
"calls",
"(",
")",
"{",
"calledWithArgs",
"=",
"append",
"(",
"calledWithArgs",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"call",
".",
"Arguments",
")",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"calledWithArgs",
")",
"==",
"0",
"{",
"return",
"assert",
".",
"Fail",
"(",
"t",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"methodName",
",",
"arguments",
")",
")",
"\n",
"}",
"\n",
"return",
"assert",
".",
"Fail",
"(",
"t",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\"",
",",
"methodName",
",",
"arguments",
",",
"strings",
".",
"Join",
"(",
"calledWithArgs",
",",
"\"",
"\\n",
"\"",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// AssertCalled asserts that the method was called.
// It can produce a false result when an argument is a pointer type and the underlying value changed after calling the mocked method.
|
[
"AssertCalled",
"asserts",
"that",
"the",
"method",
"was",
"called",
".",
"It",
"can",
"produce",
"a",
"false",
"result",
"when",
"an",
"argument",
"is",
"a",
"pointer",
"type",
"and",
"the",
"underlying",
"value",
"changed",
"after",
"calling",
"the",
"mocked",
"method",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L486-L505
|
21,208
|
stretchr/testify
|
mock/mock.go
|
AssertNotCalled
|
func (m *Mock) AssertNotCalled(t TestingT, methodName string, arguments ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
m.mutex.Lock()
defer m.mutex.Unlock()
if m.methodWasCalled(methodName, arguments) {
return assert.Fail(t, "Should not have called with given arguments",
fmt.Sprintf("Expected %q to not have been called with:\n%v\nbut actually it was.", methodName, arguments))
}
return true
}
|
go
|
func (m *Mock) AssertNotCalled(t TestingT, methodName string, arguments ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
m.mutex.Lock()
defer m.mutex.Unlock()
if m.methodWasCalled(methodName, arguments) {
return assert.Fail(t, "Should not have called with given arguments",
fmt.Sprintf("Expected %q to not have been called with:\n%v\nbut actually it was.", methodName, arguments))
}
return true
}
|
[
"func",
"(",
"m",
"*",
"Mock",
")",
"AssertNotCalled",
"(",
"t",
"TestingT",
",",
"methodName",
"string",
",",
"arguments",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n",
"m",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"m",
".",
"methodWasCalled",
"(",
"methodName",
",",
"arguments",
")",
"{",
"return",
"assert",
".",
"Fail",
"(",
"t",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"methodName",
",",
"arguments",
")",
")",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// AssertNotCalled asserts that the method was not called.
// It can produce a false result when an argument is a pointer type and the underlying value changed after calling the mocked method.
|
[
"AssertNotCalled",
"asserts",
"that",
"the",
"method",
"was",
"not",
"called",
".",
"It",
"can",
"produce",
"a",
"false",
"result",
"when",
"an",
"argument",
"is",
"a",
"pointer",
"type",
"and",
"the",
"underlying",
"value",
"changed",
"after",
"calling",
"the",
"mocked",
"method",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L509-L520
|
21,209
|
stretchr/testify
|
mock/mock.go
|
Get
|
func (args Arguments) Get(index int) interface{} {
if index+1 > len(args) {
panic(fmt.Sprintf("assert: arguments: Cannot call Get(%d) because there are %d argument(s).", index, len(args)))
}
return args[index]
}
|
go
|
func (args Arguments) Get(index int) interface{} {
if index+1 > len(args) {
panic(fmt.Sprintf("assert: arguments: Cannot call Get(%d) because there are %d argument(s).", index, len(args)))
}
return args[index]
}
|
[
"func",
"(",
"args",
"Arguments",
")",
"Get",
"(",
"index",
"int",
")",
"interface",
"{",
"}",
"{",
"if",
"index",
"+",
"1",
">",
"len",
"(",
"args",
")",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"index",
",",
"len",
"(",
"args",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"args",
"[",
"index",
"]",
"\n",
"}"
] |
// Get Returns the argument at the specified index.
|
[
"Get",
"Returns",
"the",
"argument",
"at",
"the",
"specified",
"index",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L638-L643
|
21,210
|
stretchr/testify
|
mock/mock.go
|
Is
|
func (args Arguments) Is(objects ...interface{}) bool {
for i, obj := range args {
if obj != objects[i] {
return false
}
}
return true
}
|
go
|
func (args Arguments) Is(objects ...interface{}) bool {
for i, obj := range args {
if obj != objects[i] {
return false
}
}
return true
}
|
[
"func",
"(",
"args",
"Arguments",
")",
"Is",
"(",
"objects",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"for",
"i",
",",
"obj",
":=",
"range",
"args",
"{",
"if",
"obj",
"!=",
"objects",
"[",
"i",
"]",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] |
// Is gets whether the objects match the arguments specified.
|
[
"Is",
"gets",
"whether",
"the",
"objects",
"match",
"the",
"arguments",
"specified",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L646-L653
|
21,211
|
stretchr/testify
|
mock/mock.go
|
Diff
|
func (args Arguments) Diff(objects []interface{}) (string, int) {
//TODO: could return string as error and nil for No difference
var output = "\n"
var differences int
var maxArgCount = len(args)
if len(objects) > maxArgCount {
maxArgCount = len(objects)
}
for i := 0; i < maxArgCount; i++ {
var actual, expected interface{}
var actualFmt, expectedFmt string
if len(objects) <= i {
actual = "(Missing)"
actualFmt = "(Missing)"
} else {
actual = objects[i]
actualFmt = fmt.Sprintf("(%[1]T=%[1]v)", actual)
}
if len(args) <= i {
expected = "(Missing)"
expectedFmt = "(Missing)"
} else {
expected = args[i]
expectedFmt = fmt.Sprintf("(%[1]T=%[1]v)", expected)
}
if matcher, ok := expected.(argumentMatcher); ok {
if matcher.Matches(actual) {
output = fmt.Sprintf("%s\t%d: PASS: %s matched by %s\n", output, i, actualFmt, matcher)
} else {
differences++
output = fmt.Sprintf("%s\t%d: FAIL: %s not matched by %s\n", output, i, actualFmt, matcher)
}
} else if reflect.TypeOf(expected) == reflect.TypeOf((*AnythingOfTypeArgument)(nil)).Elem() {
// type checking
if reflect.TypeOf(actual).Name() != string(expected.(AnythingOfTypeArgument)) && reflect.TypeOf(actual).String() != string(expected.(AnythingOfTypeArgument)) {
// not match
differences++
output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, expected, reflect.TypeOf(actual).Name(), actualFmt)
}
} else {
// normal checking
if assert.ObjectsAreEqual(expected, Anything) || assert.ObjectsAreEqual(actual, Anything) || assert.ObjectsAreEqual(actual, expected) {
// match
output = fmt.Sprintf("%s\t%d: PASS: %s == %s\n", output, i, actualFmt, expectedFmt)
} else {
// not match
differences++
output = fmt.Sprintf("%s\t%d: FAIL: %s != %s\n", output, i, actualFmt, expectedFmt)
}
}
}
if differences == 0 {
return "No differences.", differences
}
return output, differences
}
|
go
|
func (args Arguments) Diff(objects []interface{}) (string, int) {
//TODO: could return string as error and nil for No difference
var output = "\n"
var differences int
var maxArgCount = len(args)
if len(objects) > maxArgCount {
maxArgCount = len(objects)
}
for i := 0; i < maxArgCount; i++ {
var actual, expected interface{}
var actualFmt, expectedFmt string
if len(objects) <= i {
actual = "(Missing)"
actualFmt = "(Missing)"
} else {
actual = objects[i]
actualFmt = fmt.Sprintf("(%[1]T=%[1]v)", actual)
}
if len(args) <= i {
expected = "(Missing)"
expectedFmt = "(Missing)"
} else {
expected = args[i]
expectedFmt = fmt.Sprintf("(%[1]T=%[1]v)", expected)
}
if matcher, ok := expected.(argumentMatcher); ok {
if matcher.Matches(actual) {
output = fmt.Sprintf("%s\t%d: PASS: %s matched by %s\n", output, i, actualFmt, matcher)
} else {
differences++
output = fmt.Sprintf("%s\t%d: FAIL: %s not matched by %s\n", output, i, actualFmt, matcher)
}
} else if reflect.TypeOf(expected) == reflect.TypeOf((*AnythingOfTypeArgument)(nil)).Elem() {
// type checking
if reflect.TypeOf(actual).Name() != string(expected.(AnythingOfTypeArgument)) && reflect.TypeOf(actual).String() != string(expected.(AnythingOfTypeArgument)) {
// not match
differences++
output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, expected, reflect.TypeOf(actual).Name(), actualFmt)
}
} else {
// normal checking
if assert.ObjectsAreEqual(expected, Anything) || assert.ObjectsAreEqual(actual, Anything) || assert.ObjectsAreEqual(actual, expected) {
// match
output = fmt.Sprintf("%s\t%d: PASS: %s == %s\n", output, i, actualFmt, expectedFmt)
} else {
// not match
differences++
output = fmt.Sprintf("%s\t%d: FAIL: %s != %s\n", output, i, actualFmt, expectedFmt)
}
}
}
if differences == 0 {
return "No differences.", differences
}
return output, differences
}
|
[
"func",
"(",
"args",
"Arguments",
")",
"Diff",
"(",
"objects",
"[",
"]",
"interface",
"{",
"}",
")",
"(",
"string",
",",
"int",
")",
"{",
"//TODO: could return string as error and nil for No difference",
"var",
"output",
"=",
"\"",
"\\n",
"\"",
"\n",
"var",
"differences",
"int",
"\n\n",
"var",
"maxArgCount",
"=",
"len",
"(",
"args",
")",
"\n",
"if",
"len",
"(",
"objects",
")",
">",
"maxArgCount",
"{",
"maxArgCount",
"=",
"len",
"(",
"objects",
")",
"\n",
"}",
"\n\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"maxArgCount",
";",
"i",
"++",
"{",
"var",
"actual",
",",
"expected",
"interface",
"{",
"}",
"\n",
"var",
"actualFmt",
",",
"expectedFmt",
"string",
"\n\n",
"if",
"len",
"(",
"objects",
")",
"<=",
"i",
"{",
"actual",
"=",
"\"",
"\"",
"\n",
"actualFmt",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"actual",
"=",
"objects",
"[",
"i",
"]",
"\n",
"actualFmt",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"actual",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"args",
")",
"<=",
"i",
"{",
"expected",
"=",
"\"",
"\"",
"\n",
"expectedFmt",
"=",
"\"",
"\"",
"\n",
"}",
"else",
"{",
"expected",
"=",
"args",
"[",
"i",
"]",
"\n",
"expectedFmt",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"expected",
")",
"\n",
"}",
"\n\n",
"if",
"matcher",
",",
"ok",
":=",
"expected",
".",
"(",
"argumentMatcher",
")",
";",
"ok",
"{",
"if",
"matcher",
".",
"Matches",
"(",
"actual",
")",
"{",
"output",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\t",
"\\n",
"\"",
",",
"output",
",",
"i",
",",
"actualFmt",
",",
"matcher",
")",
"\n",
"}",
"else",
"{",
"differences",
"++",
"\n",
"output",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\t",
"\\n",
"\"",
",",
"output",
",",
"i",
",",
"actualFmt",
",",
"matcher",
")",
"\n",
"}",
"\n",
"}",
"else",
"if",
"reflect",
".",
"TypeOf",
"(",
"expected",
")",
"==",
"reflect",
".",
"TypeOf",
"(",
"(",
"*",
"AnythingOfTypeArgument",
")",
"(",
"nil",
")",
")",
".",
"Elem",
"(",
")",
"{",
"// type checking",
"if",
"reflect",
".",
"TypeOf",
"(",
"actual",
")",
".",
"Name",
"(",
")",
"!=",
"string",
"(",
"expected",
".",
"(",
"AnythingOfTypeArgument",
")",
")",
"&&",
"reflect",
".",
"TypeOf",
"(",
"actual",
")",
".",
"String",
"(",
")",
"!=",
"string",
"(",
"expected",
".",
"(",
"AnythingOfTypeArgument",
")",
")",
"{",
"// not match",
"differences",
"++",
"\n",
"output",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\t",
"\\n",
"\"",
",",
"output",
",",
"i",
",",
"expected",
",",
"reflect",
".",
"TypeOf",
"(",
"actual",
")",
".",
"Name",
"(",
")",
",",
"actualFmt",
")",
"\n",
"}",
"\n\n",
"}",
"else",
"{",
"// normal checking",
"if",
"assert",
".",
"ObjectsAreEqual",
"(",
"expected",
",",
"Anything",
")",
"||",
"assert",
".",
"ObjectsAreEqual",
"(",
"actual",
",",
"Anything",
")",
"||",
"assert",
".",
"ObjectsAreEqual",
"(",
"actual",
",",
"expected",
")",
"{",
"// match",
"output",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\t",
"\\n",
"\"",
",",
"output",
",",
"i",
",",
"actualFmt",
",",
"expectedFmt",
")",
"\n",
"}",
"else",
"{",
"// not match",
"differences",
"++",
"\n",
"output",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\t",
"\\n",
"\"",
",",
"output",
",",
"i",
",",
"actualFmt",
",",
"expectedFmt",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"}",
"\n\n",
"if",
"differences",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"differences",
"\n",
"}",
"\n\n",
"return",
"output",
",",
"differences",
"\n\n",
"}"
] |
// Diff gets a string describing the differences between the arguments
// and the specified objects.
//
// Returns the diff string and number of differences found.
|
[
"Diff",
"gets",
"a",
"string",
"describing",
"the",
"differences",
"between",
"the",
"arguments",
"and",
"the",
"specified",
"objects",
".",
"Returns",
"the",
"diff",
"string",
"and",
"number",
"of",
"differences",
"found",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L659-L728
|
21,212
|
stretchr/testify
|
mock/mock.go
|
Assert
|
func (args Arguments) Assert(t TestingT, objects ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
// get the differences
diff, diffCount := args.Diff(objects)
if diffCount == 0 {
return true
}
// there are differences... report them...
t.Logf(diff)
t.Errorf("%sArguments do not match.", assert.CallerInfo())
return false
}
|
go
|
func (args Arguments) Assert(t TestingT, objects ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
// get the differences
diff, diffCount := args.Diff(objects)
if diffCount == 0 {
return true
}
// there are differences... report them...
t.Logf(diff)
t.Errorf("%sArguments do not match.", assert.CallerInfo())
return false
}
|
[
"func",
"(",
"args",
"Arguments",
")",
"Assert",
"(",
"t",
"TestingT",
",",
"objects",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n\n",
"// get the differences",
"diff",
",",
"diffCount",
":=",
"args",
".",
"Diff",
"(",
"objects",
")",
"\n\n",
"if",
"diffCount",
"==",
"0",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"// there are differences... report them...",
"t",
".",
"Logf",
"(",
"diff",
")",
"\n",
"t",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"assert",
".",
"CallerInfo",
"(",
")",
")",
"\n\n",
"return",
"false",
"\n\n",
"}"
] |
// Assert compares the arguments with the specified objects and fails if
// they do not exactly match.
|
[
"Assert",
"compares",
"the",
"arguments",
"with",
"the",
"specified",
"objects",
"and",
"fails",
"if",
"they",
"do",
"not",
"exactly",
"match",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L732-L750
|
21,213
|
stretchr/testify
|
mock/mock.go
|
Int
|
func (args Arguments) Int(index int) int {
var s int
var ok bool
if s, ok = args.Get(index).(int); !ok {
panic(fmt.Sprintf("assert: arguments: Int(%d) failed because object wasn't correct type: %v", index, args.Get(index)))
}
return s
}
|
go
|
func (args Arguments) Int(index int) int {
var s int
var ok bool
if s, ok = args.Get(index).(int); !ok {
panic(fmt.Sprintf("assert: arguments: Int(%d) failed because object wasn't correct type: %v", index, args.Get(index)))
}
return s
}
|
[
"func",
"(",
"args",
"Arguments",
")",
"Int",
"(",
"index",
"int",
")",
"int",
"{",
"var",
"s",
"int",
"\n",
"var",
"ok",
"bool",
"\n",
"if",
"s",
",",
"ok",
"=",
"args",
".",
"Get",
"(",
"index",
")",
".",
"(",
"int",
")",
";",
"!",
"ok",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"index",
",",
"args",
".",
"Get",
"(",
"index",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// Int gets the argument at the specified index. Panics if there is no argument, or
// if the argument is of the wrong type.
|
[
"Int",
"gets",
"the",
"argument",
"at",
"the",
"specified",
"index",
".",
"Panics",
"if",
"there",
"is",
"no",
"argument",
"or",
"if",
"the",
"argument",
"is",
"of",
"the",
"wrong",
"type",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L783-L790
|
21,214
|
stretchr/testify
|
mock/mock.go
|
Error
|
func (args Arguments) Error(index int) error {
obj := args.Get(index)
var s error
var ok bool
if obj == nil {
return nil
}
if s, ok = obj.(error); !ok {
panic(fmt.Sprintf("assert: arguments: Error(%d) failed because object wasn't correct type: %v", index, args.Get(index)))
}
return s
}
|
go
|
func (args Arguments) Error(index int) error {
obj := args.Get(index)
var s error
var ok bool
if obj == nil {
return nil
}
if s, ok = obj.(error); !ok {
panic(fmt.Sprintf("assert: arguments: Error(%d) failed because object wasn't correct type: %v", index, args.Get(index)))
}
return s
}
|
[
"func",
"(",
"args",
"Arguments",
")",
"Error",
"(",
"index",
"int",
")",
"error",
"{",
"obj",
":=",
"args",
".",
"Get",
"(",
"index",
")",
"\n",
"var",
"s",
"error",
"\n",
"var",
"ok",
"bool",
"\n",
"if",
"obj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
"s",
",",
"ok",
"=",
"obj",
".",
"(",
"error",
")",
";",
"!",
"ok",
"{",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"index",
",",
"args",
".",
"Get",
"(",
"index",
")",
")",
")",
"\n",
"}",
"\n",
"return",
"s",
"\n",
"}"
] |
// Error gets the argument at the specified index. Panics if there is no argument, or
// if the argument is of the wrong type.
|
[
"Error",
"gets",
"the",
"argument",
"at",
"the",
"specified",
"index",
".",
"Panics",
"if",
"there",
"is",
"no",
"argument",
"or",
"if",
"the",
"argument",
"is",
"of",
"the",
"wrong",
"type",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/mock/mock.go#L794-L805
|
21,215
|
stretchr/testify
|
require/require.go
|
DirExists
|
func DirExists(t TestingT, path string, msgAndArgs ...interface{}) {
if h, ok := t.(tHelper); ok {
h.Helper()
}
if assert.DirExists(t, path, msgAndArgs...) {
return
}
t.FailNow()
}
|
go
|
func DirExists(t TestingT, path string, msgAndArgs ...interface{}) {
if h, ok := t.(tHelper); ok {
h.Helper()
}
if assert.DirExists(t, path, msgAndArgs...) {
return
}
t.FailNow()
}
|
[
"func",
"DirExists",
"(",
"t",
"TestingT",
",",
"path",
"string",
",",
"msgAndArgs",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n",
"if",
"assert",
".",
"DirExists",
"(",
"t",
",",
"path",
",",
"msgAndArgs",
"...",
")",
"{",
"return",
"\n",
"}",
"\n",
"t",
".",
"FailNow",
"(",
")",
"\n",
"}"
] |
// DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
|
[
"DirExists",
"checks",
"whether",
"a",
"directory",
"exists",
"in",
"the",
"given",
"path",
".",
"It",
"also",
"fails",
"if",
"the",
"path",
"is",
"a",
"file",
"rather",
"a",
"directory",
"or",
"there",
"is",
"an",
"error",
"checking",
"whether",
"it",
"exists",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/require/require.go#L70-L78
|
21,216
|
stretchr/testify
|
require/require.go
|
FailNowf
|
func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) {
if h, ok := t.(tHelper); ok {
h.Helper()
}
if assert.FailNowf(t, failureMessage, msg, args...) {
return
}
t.FailNow()
}
|
go
|
func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) {
if h, ok := t.(tHelper); ok {
h.Helper()
}
if assert.FailNowf(t, failureMessage, msg, args...) {
return
}
t.FailNow()
}
|
[
"func",
"FailNowf",
"(",
"t",
"TestingT",
",",
"failureMessage",
"string",
",",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"{",
"if",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n",
"if",
"assert",
".",
"FailNowf",
"(",
"t",
",",
"failureMessage",
",",
"msg",
",",
"args",
"...",
")",
"{",
"return",
"\n",
"}",
"\n",
"t",
".",
"FailNow",
"(",
")",
"\n",
"}"
] |
// FailNowf fails test
|
[
"FailNowf",
"fails",
"test"
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/require/require.go#L322-L330
|
21,217
|
stretchr/testify
|
assert/assertion_forward.go
|
NotZero
|
func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) bool {
if h, ok := a.t.(tHelper); ok {
h.Helper()
}
return NotZero(a.t, i, msgAndArgs...)
}
|
go
|
func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) bool {
if h, ok := a.t.(tHelper); ok {
h.Helper()
}
return NotZero(a.t, i, msgAndArgs...)
}
|
[
"func",
"(",
"a",
"*",
"Assertions",
")",
"NotZero",
"(",
"i",
"interface",
"{",
"}",
",",
"msgAndArgs",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"h",
",",
"ok",
":=",
"a",
".",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n",
"return",
"NotZero",
"(",
"a",
".",
"t",
",",
"i",
",",
"msgAndArgs",
"...",
")",
"\n",
"}"
] |
// NotZero asserts that i is not the zero value for its type.
|
[
"NotZero",
"asserts",
"that",
"i",
"is",
"not",
"the",
"zero",
"value",
"for",
"its",
"type",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/assert/assertion_forward.go#L901-L906
|
21,218
|
stretchr/testify
|
assert/http_assertions.go
|
HTTPBody
|
func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values) string {
w := httptest.NewRecorder()
req, err := http.NewRequest(method, url+"?"+values.Encode(), nil)
if err != nil {
return ""
}
handler(w, req)
return w.Body.String()
}
|
go
|
func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values) string {
w := httptest.NewRecorder()
req, err := http.NewRequest(method, url+"?"+values.Encode(), nil)
if err != nil {
return ""
}
handler(w, req)
return w.Body.String()
}
|
[
"func",
"HTTPBody",
"(",
"handler",
"http",
".",
"HandlerFunc",
",",
"method",
",",
"url",
"string",
",",
"values",
"url",
".",
"Values",
")",
"string",
"{",
"w",
":=",
"httptest",
".",
"NewRecorder",
"(",
")",
"\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"method",
",",
"url",
"+",
"\"",
"\"",
"+",
"values",
".",
"Encode",
"(",
")",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"handler",
"(",
"w",
",",
"req",
")",
"\n",
"return",
"w",
".",
"Body",
".",
"String",
"(",
")",
"\n",
"}"
] |
// HTTPBody is a helper that returns HTTP body of the response. It returns
// empty string if building a new request fails.
|
[
"HTTPBody",
"is",
"a",
"helper",
"that",
"returns",
"HTTP",
"body",
"of",
"the",
"response",
".",
"It",
"returns",
"empty",
"string",
"if",
"building",
"a",
"new",
"request",
"fails",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/assert/http_assertions.go#L95-L103
|
21,219
|
stretchr/testify
|
suite/suite.go
|
Require
|
func (suite *Suite) Require() *require.Assertions {
if suite.require == nil {
suite.require = require.New(suite.T())
}
return suite.require
}
|
go
|
func (suite *Suite) Require() *require.Assertions {
if suite.require == nil {
suite.require = require.New(suite.T())
}
return suite.require
}
|
[
"func",
"(",
"suite",
"*",
"Suite",
")",
"Require",
"(",
")",
"*",
"require",
".",
"Assertions",
"{",
"if",
"suite",
".",
"require",
"==",
"nil",
"{",
"suite",
".",
"require",
"=",
"require",
".",
"New",
"(",
"suite",
".",
"T",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"suite",
".",
"require",
"\n",
"}"
] |
// Require returns a require context for suite.
|
[
"Require",
"returns",
"a",
"require",
"context",
"for",
"suite",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/suite/suite.go#L40-L45
|
21,220
|
stretchr/testify
|
suite/suite.go
|
Run
|
func Run(t *testing.T, suite TestingSuite) {
suite.SetT(t)
defer failOnPanic(t)
suiteSetupDone := false
methodFinder := reflect.TypeOf(suite)
tests := []testing.InternalTest{}
for index := 0; index < methodFinder.NumMethod(); index++ {
method := methodFinder.Method(index)
ok, err := methodFilter(method.Name)
if err != nil {
fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err)
os.Exit(1)
}
if !ok {
continue
}
if !suiteSetupDone {
if setupAllSuite, ok := suite.(SetupAllSuite); ok {
setupAllSuite.SetupSuite()
}
defer func() {
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
tearDownAllSuite.TearDownSuite()
}
}()
suiteSetupDone = true
}
test := testing.InternalTest{
Name: method.Name,
F: func(t *testing.T) {
parentT := suite.T()
suite.SetT(t)
defer failOnPanic(t)
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
setupTestSuite.SetupTest()
}
if beforeTestSuite, ok := suite.(BeforeTest); ok {
beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
}
defer func() {
if afterTestSuite, ok := suite.(AfterTest); ok {
afterTestSuite.AfterTest(methodFinder.Elem().Name(), method.Name)
}
if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
tearDownTestSuite.TearDownTest()
}
suite.SetT(parentT)
}()
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
},
}
tests = append(tests, test)
}
runTests(t, tests)
}
|
go
|
func Run(t *testing.T, suite TestingSuite) {
suite.SetT(t)
defer failOnPanic(t)
suiteSetupDone := false
methodFinder := reflect.TypeOf(suite)
tests := []testing.InternalTest{}
for index := 0; index < methodFinder.NumMethod(); index++ {
method := methodFinder.Method(index)
ok, err := methodFilter(method.Name)
if err != nil {
fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err)
os.Exit(1)
}
if !ok {
continue
}
if !suiteSetupDone {
if setupAllSuite, ok := suite.(SetupAllSuite); ok {
setupAllSuite.SetupSuite()
}
defer func() {
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
tearDownAllSuite.TearDownSuite()
}
}()
suiteSetupDone = true
}
test := testing.InternalTest{
Name: method.Name,
F: func(t *testing.T) {
parentT := suite.T()
suite.SetT(t)
defer failOnPanic(t)
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
setupTestSuite.SetupTest()
}
if beforeTestSuite, ok := suite.(BeforeTest); ok {
beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
}
defer func() {
if afterTestSuite, ok := suite.(AfterTest); ok {
afterTestSuite.AfterTest(methodFinder.Elem().Name(), method.Name)
}
if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
tearDownTestSuite.TearDownTest()
}
suite.SetT(parentT)
}()
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
},
}
tests = append(tests, test)
}
runTests(t, tests)
}
|
[
"func",
"Run",
"(",
"t",
"*",
"testing",
".",
"T",
",",
"suite",
"TestingSuite",
")",
"{",
"suite",
".",
"SetT",
"(",
"t",
")",
"\n",
"defer",
"failOnPanic",
"(",
"t",
")",
"\n\n",
"suiteSetupDone",
":=",
"false",
"\n",
"methodFinder",
":=",
"reflect",
".",
"TypeOf",
"(",
"suite",
")",
"\n",
"tests",
":=",
"[",
"]",
"testing",
".",
"InternalTest",
"{",
"}",
"\n",
"for",
"index",
":=",
"0",
";",
"index",
"<",
"methodFinder",
".",
"NumMethod",
"(",
")",
";",
"index",
"++",
"{",
"method",
":=",
"methodFinder",
".",
"Method",
"(",
"index",
")",
"\n",
"ok",
",",
"err",
":=",
"methodFilter",
"(",
"method",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"os",
".",
"Exit",
"(",
"1",
")",
"\n",
"}",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"!",
"suiteSetupDone",
"{",
"if",
"setupAllSuite",
",",
"ok",
":=",
"suite",
".",
"(",
"SetupAllSuite",
")",
";",
"ok",
"{",
"setupAllSuite",
".",
"SetupSuite",
"(",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"tearDownAllSuite",
",",
"ok",
":=",
"suite",
".",
"(",
"TearDownAllSuite",
")",
";",
"ok",
"{",
"tearDownAllSuite",
".",
"TearDownSuite",
"(",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n",
"suiteSetupDone",
"=",
"true",
"\n",
"}",
"\n",
"test",
":=",
"testing",
".",
"InternalTest",
"{",
"Name",
":",
"method",
".",
"Name",
",",
"F",
":",
"func",
"(",
"t",
"*",
"testing",
".",
"T",
")",
"{",
"parentT",
":=",
"suite",
".",
"T",
"(",
")",
"\n",
"suite",
".",
"SetT",
"(",
"t",
")",
"\n",
"defer",
"failOnPanic",
"(",
"t",
")",
"\n\n",
"if",
"setupTestSuite",
",",
"ok",
":=",
"suite",
".",
"(",
"SetupTestSuite",
")",
";",
"ok",
"{",
"setupTestSuite",
".",
"SetupTest",
"(",
")",
"\n",
"}",
"\n",
"if",
"beforeTestSuite",
",",
"ok",
":=",
"suite",
".",
"(",
"BeforeTest",
")",
";",
"ok",
"{",
"beforeTestSuite",
".",
"BeforeTest",
"(",
"methodFinder",
".",
"Elem",
"(",
")",
".",
"Name",
"(",
")",
",",
"method",
".",
"Name",
")",
"\n",
"}",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"afterTestSuite",
",",
"ok",
":=",
"suite",
".",
"(",
"AfterTest",
")",
";",
"ok",
"{",
"afterTestSuite",
".",
"AfterTest",
"(",
"methodFinder",
".",
"Elem",
"(",
")",
".",
"Name",
"(",
")",
",",
"method",
".",
"Name",
")",
"\n",
"}",
"\n",
"if",
"tearDownTestSuite",
",",
"ok",
":=",
"suite",
".",
"(",
"TearDownTestSuite",
")",
";",
"ok",
"{",
"tearDownTestSuite",
".",
"TearDownTest",
"(",
")",
"\n",
"}",
"\n",
"suite",
".",
"SetT",
"(",
"parentT",
")",
"\n",
"}",
"(",
")",
"\n",
"method",
".",
"Func",
".",
"Call",
"(",
"[",
"]",
"reflect",
".",
"Value",
"{",
"reflect",
".",
"ValueOf",
"(",
"suite",
")",
"}",
")",
"\n",
"}",
",",
"}",
"\n",
"tests",
"=",
"append",
"(",
"tests",
",",
"test",
")",
"\n",
"}",
"\n",
"runTests",
"(",
"t",
",",
"tests",
")",
"\n",
"}"
] |
// Run takes a testing suite and runs all of the tests attached
// to it.
|
[
"Run",
"takes",
"a",
"testing",
"suite",
"and",
"runs",
"all",
"of",
"the",
"tests",
"attached",
"to",
"it",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/suite/suite.go#L82-L139
|
21,221
|
stretchr/testify
|
suite/suite.go
|
methodFilter
|
func methodFilter(name string) (bool, error) {
if ok, _ := regexp.MatchString("^Test", name); !ok {
return false, nil
}
return regexp.MatchString(*matchMethod, name)
}
|
go
|
func methodFilter(name string) (bool, error) {
if ok, _ := regexp.MatchString("^Test", name); !ok {
return false, nil
}
return regexp.MatchString(*matchMethod, name)
}
|
[
"func",
"methodFilter",
"(",
"name",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"ok",
",",
"_",
":=",
"regexp",
".",
"MatchString",
"(",
"\"",
"\"",
",",
"name",
")",
";",
"!",
"ok",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"regexp",
".",
"MatchString",
"(",
"*",
"matchMethod",
",",
"name",
")",
"\n",
"}"
] |
// Filtering method according to set regular expression
// specified command-line argument -m
|
[
"Filtering",
"method",
"according",
"to",
"set",
"regular",
"expression",
"specified",
"command",
"-",
"line",
"argument",
"-",
"m"
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/suite/suite.go#L157-L162
|
21,222
|
stretchr/testify
|
assert/assertion_format.go
|
InEpsilonf
|
func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
return InEpsilon(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...)
}
|
go
|
func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, msg string, args ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
return InEpsilon(t, expected, actual, epsilon, append([]interface{}{msg}, args...)...)
}
|
[
"func",
"InEpsilonf",
"(",
"t",
"TestingT",
",",
"expected",
"interface",
"{",
"}",
",",
"actual",
"interface",
"{",
"}",
",",
"epsilon",
"float64",
",",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n",
"return",
"InEpsilon",
"(",
"t",
",",
"expected",
",",
"actual",
",",
"epsilon",
",",
"append",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"msg",
"}",
",",
"args",
"...",
")",
"...",
")",
"\n",
"}"
] |
// InEpsilonf asserts that expected and actual have a relative error less than epsilon
|
[
"InEpsilonf",
"asserts",
"that",
"expected",
"and",
"actual",
"have",
"a",
"relative",
"error",
"less",
"than",
"epsilon"
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/assert/assertion_format.go#L284-L289
|
21,223
|
stretchr/testify
|
assert/assertion_format.go
|
NotZerof
|
func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
return NotZero(t, i, append([]interface{}{msg}, args...)...)
}
|
go
|
func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
return NotZero(t, i, append([]interface{}{msg}, args...)...)
}
|
[
"func",
"NotZerof",
"(",
"t",
"TestingT",
",",
"i",
"interface",
"{",
"}",
",",
"msg",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n",
"return",
"NotZero",
"(",
"t",
",",
"i",
",",
"append",
"(",
"[",
"]",
"interface",
"{",
"}",
"{",
"msg",
"}",
",",
"args",
"...",
")",
"...",
")",
"\n",
"}"
] |
// NotZerof asserts that i is not the zero value for its type.
|
[
"NotZerof",
"asserts",
"that",
"i",
"is",
"not",
"the",
"zero",
"value",
"for",
"its",
"type",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/assert/assertion_format.go#L458-L463
|
21,224
|
stretchr/testify
|
_codegen/main.go
|
parsePackageSource
|
func parsePackageSource(pkg string) (*types.Scope, *doc.Package, error) {
pd, err := build.Import(pkg, ".", 0)
if err != nil {
return nil, nil, err
}
fset := token.NewFileSet()
files := make(map[string]*ast.File)
fileList := make([]*ast.File, len(pd.GoFiles))
for i, fname := range pd.GoFiles {
src, err := ioutil.ReadFile(path.Join(pd.SrcRoot, pd.ImportPath, fname))
if err != nil {
return nil, nil, err
}
f, err := parser.ParseFile(fset, fname, src, parser.ParseComments|parser.AllErrors)
if err != nil {
return nil, nil, err
}
files[fname] = f
fileList[i] = f
}
cfg := types.Config{
Importer: importer.Default(),
}
info := types.Info{
Defs: make(map[*ast.Ident]types.Object),
}
tp, err := cfg.Check(pkg, fset, fileList, &info)
if err != nil {
return nil, nil, err
}
scope := tp.Scope()
ap, _ := ast.NewPackage(fset, files, nil, nil)
docs := doc.New(ap, pkg, 0)
return scope, docs, nil
}
|
go
|
func parsePackageSource(pkg string) (*types.Scope, *doc.Package, error) {
pd, err := build.Import(pkg, ".", 0)
if err != nil {
return nil, nil, err
}
fset := token.NewFileSet()
files := make(map[string]*ast.File)
fileList := make([]*ast.File, len(pd.GoFiles))
for i, fname := range pd.GoFiles {
src, err := ioutil.ReadFile(path.Join(pd.SrcRoot, pd.ImportPath, fname))
if err != nil {
return nil, nil, err
}
f, err := parser.ParseFile(fset, fname, src, parser.ParseComments|parser.AllErrors)
if err != nil {
return nil, nil, err
}
files[fname] = f
fileList[i] = f
}
cfg := types.Config{
Importer: importer.Default(),
}
info := types.Info{
Defs: make(map[*ast.Ident]types.Object),
}
tp, err := cfg.Check(pkg, fset, fileList, &info)
if err != nil {
return nil, nil, err
}
scope := tp.Scope()
ap, _ := ast.NewPackage(fset, files, nil, nil)
docs := doc.New(ap, pkg, 0)
return scope, docs, nil
}
|
[
"func",
"parsePackageSource",
"(",
"pkg",
"string",
")",
"(",
"*",
"types",
".",
"Scope",
",",
"*",
"doc",
".",
"Package",
",",
"error",
")",
"{",
"pd",
",",
"err",
":=",
"build",
".",
"Import",
"(",
"pkg",
",",
"\"",
"\"",
",",
"0",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"fset",
":=",
"token",
".",
"NewFileSet",
"(",
")",
"\n",
"files",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"ast",
".",
"File",
")",
"\n",
"fileList",
":=",
"make",
"(",
"[",
"]",
"*",
"ast",
".",
"File",
",",
"len",
"(",
"pd",
".",
"GoFiles",
")",
")",
"\n",
"for",
"i",
",",
"fname",
":=",
"range",
"pd",
".",
"GoFiles",
"{",
"src",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"path",
".",
"Join",
"(",
"pd",
".",
"SrcRoot",
",",
"pd",
".",
"ImportPath",
",",
"fname",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"f",
",",
"err",
":=",
"parser",
".",
"ParseFile",
"(",
"fset",
",",
"fname",
",",
"src",
",",
"parser",
".",
"ParseComments",
"|",
"parser",
".",
"AllErrors",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"files",
"[",
"fname",
"]",
"=",
"f",
"\n",
"fileList",
"[",
"i",
"]",
"=",
"f",
"\n",
"}",
"\n\n",
"cfg",
":=",
"types",
".",
"Config",
"{",
"Importer",
":",
"importer",
".",
"Default",
"(",
")",
",",
"}",
"\n",
"info",
":=",
"types",
".",
"Info",
"{",
"Defs",
":",
"make",
"(",
"map",
"[",
"*",
"ast",
".",
"Ident",
"]",
"types",
".",
"Object",
")",
",",
"}",
"\n",
"tp",
",",
"err",
":=",
"cfg",
".",
"Check",
"(",
"pkg",
",",
"fset",
",",
"fileList",
",",
"&",
"info",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"scope",
":=",
"tp",
".",
"Scope",
"(",
")",
"\n\n",
"ap",
",",
"_",
":=",
"ast",
".",
"NewPackage",
"(",
"fset",
",",
"files",
",",
"nil",
",",
"nil",
")",
"\n",
"docs",
":=",
"doc",
".",
"New",
"(",
"ap",
",",
"pkg",
",",
"0",
")",
"\n\n",
"return",
"scope",
",",
"docs",
",",
"nil",
"\n",
"}"
] |
// parsePackageSource returns the types scope and the package documentation from the package
|
[
"parsePackageSource",
"returns",
"the",
"types",
"scope",
"and",
"the",
"package",
"documentation",
"from",
"the",
"package"
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/_codegen/main.go#L174-L213
|
21,225
|
stretchr/testify
|
assert/assertions.go
|
ObjectsAreEqualValues
|
func ObjectsAreEqualValues(expected, actual interface{}) bool {
if ObjectsAreEqual(expected, actual) {
return true
}
actualType := reflect.TypeOf(actual)
if actualType == nil {
return false
}
expectedValue := reflect.ValueOf(expected)
if expectedValue.IsValid() && expectedValue.Type().ConvertibleTo(actualType) {
// Attempt comparison after type conversion
return reflect.DeepEqual(expectedValue.Convert(actualType).Interface(), actual)
}
return false
}
|
go
|
func ObjectsAreEqualValues(expected, actual interface{}) bool {
if ObjectsAreEqual(expected, actual) {
return true
}
actualType := reflect.TypeOf(actual)
if actualType == nil {
return false
}
expectedValue := reflect.ValueOf(expected)
if expectedValue.IsValid() && expectedValue.Type().ConvertibleTo(actualType) {
// Attempt comparison after type conversion
return reflect.DeepEqual(expectedValue.Convert(actualType).Interface(), actual)
}
return false
}
|
[
"func",
"ObjectsAreEqualValues",
"(",
"expected",
",",
"actual",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"ObjectsAreEqual",
"(",
"expected",
",",
"actual",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"actualType",
":=",
"reflect",
".",
"TypeOf",
"(",
"actual",
")",
"\n",
"if",
"actualType",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"expectedValue",
":=",
"reflect",
".",
"ValueOf",
"(",
"expected",
")",
"\n",
"if",
"expectedValue",
".",
"IsValid",
"(",
")",
"&&",
"expectedValue",
".",
"Type",
"(",
")",
".",
"ConvertibleTo",
"(",
"actualType",
")",
"{",
"// Attempt comparison after type conversion",
"return",
"reflect",
".",
"DeepEqual",
"(",
"expectedValue",
".",
"Convert",
"(",
"actualType",
")",
".",
"Interface",
"(",
")",
",",
"actual",
")",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// ObjectsAreEqualValues gets whether two objects are equal, or if their
// values are equal.
|
[
"ObjectsAreEqualValues",
"gets",
"whether",
"two",
"objects",
"are",
"equal",
"or",
"if",
"their",
"values",
"are",
"equal",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/assert/assertions.go#L78-L94
|
21,226
|
stretchr/testify
|
assert/assertions.go
|
formatUnequalValues
|
func formatUnequalValues(expected, actual interface{}) (e string, a string) {
if reflect.TypeOf(expected) != reflect.TypeOf(actual) {
return fmt.Sprintf("%T(%#v)", expected, expected),
fmt.Sprintf("%T(%#v)", actual, actual)
}
return fmt.Sprintf("%#v", expected),
fmt.Sprintf("%#v", actual)
}
|
go
|
func formatUnequalValues(expected, actual interface{}) (e string, a string) {
if reflect.TypeOf(expected) != reflect.TypeOf(actual) {
return fmt.Sprintf("%T(%#v)", expected, expected),
fmt.Sprintf("%T(%#v)", actual, actual)
}
return fmt.Sprintf("%#v", expected),
fmt.Sprintf("%#v", actual)
}
|
[
"func",
"formatUnequalValues",
"(",
"expected",
",",
"actual",
"interface",
"{",
"}",
")",
"(",
"e",
"string",
",",
"a",
"string",
")",
"{",
"if",
"reflect",
".",
"TypeOf",
"(",
"expected",
")",
"!=",
"reflect",
".",
"TypeOf",
"(",
"actual",
")",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"expected",
",",
"expected",
")",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"actual",
",",
"actual",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"expected",
")",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"actual",
")",
"\n",
"}"
] |
// formatUnequalValues takes two values of arbitrary types and returns string
// representations appropriate to be presented to the user.
//
// If the values are not of like type, the returned strings will be prefixed
// with the type name, and the value will be enclosed in parenthesis similar
// to a type conversion in the Go grammar.
|
[
"formatUnequalValues",
"takes",
"two",
"values",
"of",
"arbitrary",
"types",
"and",
"returns",
"string",
"representations",
"appropriate",
"to",
"be",
"presented",
"to",
"the",
"user",
".",
"If",
"the",
"values",
"are",
"not",
"of",
"like",
"type",
"the",
"returned",
"strings",
"will",
"be",
"prefixed",
"with",
"the",
"type",
"name",
"and",
"the",
"value",
"will",
"be",
"enclosed",
"in",
"parenthesis",
"similar",
"to",
"a",
"type",
"conversion",
"in",
"the",
"Go",
"grammar",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/assert/assertions.go#L390-L398
|
21,227
|
stretchr/testify
|
assert/assertions.go
|
containsKind
|
func containsKind(kinds []reflect.Kind, kind reflect.Kind) bool {
for i := 0; i < len(kinds); i++ {
if kind == kinds[i] {
return true
}
}
return false
}
|
go
|
func containsKind(kinds []reflect.Kind, kind reflect.Kind) bool {
for i := 0; i < len(kinds); i++ {
if kind == kinds[i] {
return true
}
}
return false
}
|
[
"func",
"containsKind",
"(",
"kinds",
"[",
"]",
"reflect",
".",
"Kind",
",",
"kind",
"reflect",
".",
"Kind",
")",
"bool",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"kinds",
")",
";",
"i",
"++",
"{",
"if",
"kind",
"==",
"kinds",
"[",
"i",
"]",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// containsKind checks if a specified kind in the slice of kinds.
|
[
"containsKind",
"checks",
"if",
"a",
"specified",
"kind",
"in",
"the",
"slice",
"of",
"kinds",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/assert/assertions.go#L454-L462
|
21,228
|
stretchr/testify
|
assert/assertions.go
|
isNil
|
func isNil(object interface{}) bool {
if object == nil {
return true
}
value := reflect.ValueOf(object)
kind := value.Kind()
isNilableKind := containsKind(
[]reflect.Kind{
reflect.Chan, reflect.Func,
reflect.Interface, reflect.Map,
reflect.Ptr, reflect.Slice},
kind)
if isNilableKind && value.IsNil() {
return true
}
return false
}
|
go
|
func isNil(object interface{}) bool {
if object == nil {
return true
}
value := reflect.ValueOf(object)
kind := value.Kind()
isNilableKind := containsKind(
[]reflect.Kind{
reflect.Chan, reflect.Func,
reflect.Interface, reflect.Map,
reflect.Ptr, reflect.Slice},
kind)
if isNilableKind && value.IsNil() {
return true
}
return false
}
|
[
"func",
"isNil",
"(",
"object",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"object",
"==",
"nil",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"value",
":=",
"reflect",
".",
"ValueOf",
"(",
"object",
")",
"\n",
"kind",
":=",
"value",
".",
"Kind",
"(",
")",
"\n",
"isNilableKind",
":=",
"containsKind",
"(",
"[",
"]",
"reflect",
".",
"Kind",
"{",
"reflect",
".",
"Chan",
",",
"reflect",
".",
"Func",
",",
"reflect",
".",
"Interface",
",",
"reflect",
".",
"Map",
",",
"reflect",
".",
"Ptr",
",",
"reflect",
".",
"Slice",
"}",
",",
"kind",
")",
"\n\n",
"if",
"isNilableKind",
"&&",
"value",
".",
"IsNil",
"(",
")",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"return",
"false",
"\n",
"}"
] |
// isNil checks if a specified object is nil or not, without Failing.
|
[
"isNil",
"checks",
"if",
"a",
"specified",
"object",
"is",
"nil",
"or",
"not",
"without",
"Failing",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/assert/assertions.go#L465-L484
|
21,229
|
stretchr/testify
|
assert/assertions.go
|
didPanic
|
func didPanic(f PanicTestFunc) (bool, interface{}) {
didPanic := false
var message interface{}
func() {
defer func() {
if message = recover(); message != nil {
didPanic = true
}
}()
// call the target function
f()
}()
return didPanic, message
}
|
go
|
func didPanic(f PanicTestFunc) (bool, interface{}) {
didPanic := false
var message interface{}
func() {
defer func() {
if message = recover(); message != nil {
didPanic = true
}
}()
// call the target function
f()
}()
return didPanic, message
}
|
[
"func",
"didPanic",
"(",
"f",
"PanicTestFunc",
")",
"(",
"bool",
",",
"interface",
"{",
"}",
")",
"{",
"didPanic",
":=",
"false",
"\n",
"var",
"message",
"interface",
"{",
"}",
"\n",
"func",
"(",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"message",
"=",
"recover",
"(",
")",
";",
"message",
"!=",
"nil",
"{",
"didPanic",
"=",
"true",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"// call the target function",
"f",
"(",
")",
"\n\n",
"}",
"(",
")",
"\n\n",
"return",
"didPanic",
",",
"message",
"\n\n",
"}"
] |
// didPanic returns true if the function passed to it panics. Otherwise, it returns false.
|
[
"didPanic",
"returns",
"true",
"if",
"the",
"function",
"passed",
"to",
"it",
"panics",
".",
"Otherwise",
"it",
"returns",
"false",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/assert/assertions.go#L903-L922
|
21,230
|
stretchr/testify
|
assert/assertions.go
|
InDeltaMapValues
|
func InDeltaMapValues(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
if expected == nil || actual == nil ||
reflect.TypeOf(actual).Kind() != reflect.Map ||
reflect.TypeOf(expected).Kind() != reflect.Map {
return Fail(t, "Arguments must be maps", msgAndArgs...)
}
expectedMap := reflect.ValueOf(expected)
actualMap := reflect.ValueOf(actual)
if expectedMap.Len() != actualMap.Len() {
return Fail(t, "Arguments must have the same number of keys", msgAndArgs...)
}
for _, k := range expectedMap.MapKeys() {
ev := expectedMap.MapIndex(k)
av := actualMap.MapIndex(k)
if !ev.IsValid() {
return Fail(t, fmt.Sprintf("missing key %q in expected map", k), msgAndArgs...)
}
if !av.IsValid() {
return Fail(t, fmt.Sprintf("missing key %q in actual map", k), msgAndArgs...)
}
if !InDelta(
t,
ev.Interface(),
av.Interface(),
delta,
msgAndArgs...,
) {
return false
}
}
return true
}
|
go
|
func InDeltaMapValues(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool {
if h, ok := t.(tHelper); ok {
h.Helper()
}
if expected == nil || actual == nil ||
reflect.TypeOf(actual).Kind() != reflect.Map ||
reflect.TypeOf(expected).Kind() != reflect.Map {
return Fail(t, "Arguments must be maps", msgAndArgs...)
}
expectedMap := reflect.ValueOf(expected)
actualMap := reflect.ValueOf(actual)
if expectedMap.Len() != actualMap.Len() {
return Fail(t, "Arguments must have the same number of keys", msgAndArgs...)
}
for _, k := range expectedMap.MapKeys() {
ev := expectedMap.MapIndex(k)
av := actualMap.MapIndex(k)
if !ev.IsValid() {
return Fail(t, fmt.Sprintf("missing key %q in expected map", k), msgAndArgs...)
}
if !av.IsValid() {
return Fail(t, fmt.Sprintf("missing key %q in actual map", k), msgAndArgs...)
}
if !InDelta(
t,
ev.Interface(),
av.Interface(),
delta,
msgAndArgs...,
) {
return false
}
}
return true
}
|
[
"func",
"InDeltaMapValues",
"(",
"t",
"TestingT",
",",
"expected",
",",
"actual",
"interface",
"{",
"}",
",",
"delta",
"float64",
",",
"msgAndArgs",
"...",
"interface",
"{",
"}",
")",
"bool",
"{",
"if",
"h",
",",
"ok",
":=",
"t",
".",
"(",
"tHelper",
")",
";",
"ok",
"{",
"h",
".",
"Helper",
"(",
")",
"\n",
"}",
"\n",
"if",
"expected",
"==",
"nil",
"||",
"actual",
"==",
"nil",
"||",
"reflect",
".",
"TypeOf",
"(",
"actual",
")",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Map",
"||",
"reflect",
".",
"TypeOf",
"(",
"expected",
")",
".",
"Kind",
"(",
")",
"!=",
"reflect",
".",
"Map",
"{",
"return",
"Fail",
"(",
"t",
",",
"\"",
"\"",
",",
"msgAndArgs",
"...",
")",
"\n",
"}",
"\n\n",
"expectedMap",
":=",
"reflect",
".",
"ValueOf",
"(",
"expected",
")",
"\n",
"actualMap",
":=",
"reflect",
".",
"ValueOf",
"(",
"actual",
")",
"\n\n",
"if",
"expectedMap",
".",
"Len",
"(",
")",
"!=",
"actualMap",
".",
"Len",
"(",
")",
"{",
"return",
"Fail",
"(",
"t",
",",
"\"",
"\"",
",",
"msgAndArgs",
"...",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"k",
":=",
"range",
"expectedMap",
".",
"MapKeys",
"(",
")",
"{",
"ev",
":=",
"expectedMap",
".",
"MapIndex",
"(",
"k",
")",
"\n",
"av",
":=",
"actualMap",
".",
"MapIndex",
"(",
"k",
")",
"\n\n",
"if",
"!",
"ev",
".",
"IsValid",
"(",
")",
"{",
"return",
"Fail",
"(",
"t",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"k",
")",
",",
"msgAndArgs",
"...",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"av",
".",
"IsValid",
"(",
")",
"{",
"return",
"Fail",
"(",
"t",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"k",
")",
",",
"msgAndArgs",
"...",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"InDelta",
"(",
"t",
",",
"ev",
".",
"Interface",
"(",
")",
",",
"av",
".",
"Interface",
"(",
")",
",",
"delta",
",",
"msgAndArgs",
"...",
",",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"true",
"\n",
"}"
] |
// InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
|
[
"InDeltaMapValues",
"is",
"the",
"same",
"as",
"InDelta",
"but",
"it",
"compares",
"all",
"values",
"between",
"two",
"maps",
".",
"Both",
"maps",
"must",
"have",
"exactly",
"the",
"same",
"keys",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/assert/assertions.go#L1082-L1123
|
21,231
|
stretchr/testify
|
assert/assertions.go
|
matchRegexp
|
func matchRegexp(rx interface{}, str interface{}) bool {
var r *regexp.Regexp
if rr, ok := rx.(*regexp.Regexp); ok {
r = rr
} else {
r = regexp.MustCompile(fmt.Sprint(rx))
}
return (r.FindStringIndex(fmt.Sprint(str)) != nil)
}
|
go
|
func matchRegexp(rx interface{}, str interface{}) bool {
var r *regexp.Regexp
if rr, ok := rx.(*regexp.Regexp); ok {
r = rr
} else {
r = regexp.MustCompile(fmt.Sprint(rx))
}
return (r.FindStringIndex(fmt.Sprint(str)) != nil)
}
|
[
"func",
"matchRegexp",
"(",
"rx",
"interface",
"{",
"}",
",",
"str",
"interface",
"{",
"}",
")",
"bool",
"{",
"var",
"r",
"*",
"regexp",
".",
"Regexp",
"\n",
"if",
"rr",
",",
"ok",
":=",
"rx",
".",
"(",
"*",
"regexp",
".",
"Regexp",
")",
";",
"ok",
"{",
"r",
"=",
"rr",
"\n",
"}",
"else",
"{",
"r",
"=",
"regexp",
".",
"MustCompile",
"(",
"fmt",
".",
"Sprint",
"(",
"rx",
")",
")",
"\n",
"}",
"\n\n",
"return",
"(",
"r",
".",
"FindStringIndex",
"(",
"fmt",
".",
"Sprint",
"(",
"str",
")",
")",
"!=",
"nil",
")",
"\n\n",
"}"
] |
// matchRegexp return true if a specified regexp matches a string.
|
[
"matchRegexp",
"return",
"true",
"if",
"a",
"specified",
"regexp",
"matches",
"a",
"string",
"."
] |
34c6fa2dc70986bccbbffcc6130f6920a924b075
|
https://github.com/stretchr/testify/blob/34c6fa2dc70986bccbbffcc6130f6920a924b075/assert/assertions.go#L1245-L1256
|
21,232
|
vmware/govmomi
|
object/virtual_device_list.go
|
SCSIControllerTypes
|
func SCSIControllerTypes() VirtualDeviceList {
// Return a mutable list of SCSI controller types, initialized with defaults.
return VirtualDeviceList([]types.BaseVirtualDevice{
&types.VirtualLsiLogicController{},
&types.VirtualBusLogicController{},
&types.ParaVirtualSCSIController{},
&types.VirtualLsiLogicSASController{},
}).Select(func(device types.BaseVirtualDevice) bool {
c := device.(types.BaseVirtualSCSIController).GetVirtualSCSIController()
c.SharedBus = types.VirtualSCSISharingNoSharing
c.BusNumber = -1
return true
})
}
|
go
|
func SCSIControllerTypes() VirtualDeviceList {
// Return a mutable list of SCSI controller types, initialized with defaults.
return VirtualDeviceList([]types.BaseVirtualDevice{
&types.VirtualLsiLogicController{},
&types.VirtualBusLogicController{},
&types.ParaVirtualSCSIController{},
&types.VirtualLsiLogicSASController{},
}).Select(func(device types.BaseVirtualDevice) bool {
c := device.(types.BaseVirtualSCSIController).GetVirtualSCSIController()
c.SharedBus = types.VirtualSCSISharingNoSharing
c.BusNumber = -1
return true
})
}
|
[
"func",
"SCSIControllerTypes",
"(",
")",
"VirtualDeviceList",
"{",
"// Return a mutable list of SCSI controller types, initialized with defaults.",
"return",
"VirtualDeviceList",
"(",
"[",
"]",
"types",
".",
"BaseVirtualDevice",
"{",
"&",
"types",
".",
"VirtualLsiLogicController",
"{",
"}",
",",
"&",
"types",
".",
"VirtualBusLogicController",
"{",
"}",
",",
"&",
"types",
".",
"ParaVirtualSCSIController",
"{",
"}",
",",
"&",
"types",
".",
"VirtualLsiLogicSASController",
"{",
"}",
",",
"}",
")",
".",
"Select",
"(",
"func",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"bool",
"{",
"c",
":=",
"device",
".",
"(",
"types",
".",
"BaseVirtualSCSIController",
")",
".",
"GetVirtualSCSIController",
"(",
")",
"\n",
"c",
".",
"SharedBus",
"=",
"types",
".",
"VirtualSCSISharingNoSharing",
"\n",
"c",
".",
"BusNumber",
"=",
"-",
"1",
"\n",
"return",
"true",
"\n",
"}",
")",
"\n",
"}"
] |
// SCSIControllerTypes are used for adding a new SCSI controller to a VM.
|
[
"SCSIControllerTypes",
"are",
"used",
"for",
"adding",
"a",
"new",
"SCSI",
"controller",
"to",
"a",
"VM",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L44-L57
|
21,233
|
vmware/govmomi
|
object/virtual_device_list.go
|
EthernetCardTypes
|
func EthernetCardTypes() VirtualDeviceList {
return VirtualDeviceList([]types.BaseVirtualDevice{
&types.VirtualE1000{},
&types.VirtualE1000e{},
&types.VirtualVmxnet2{},
&types.VirtualVmxnet3{},
&types.VirtualPCNet32{},
&types.VirtualSriovEthernetCard{},
}).Select(func(device types.BaseVirtualDevice) bool {
c := device.(types.BaseVirtualEthernetCard).GetVirtualEthernetCard()
c.GetVirtualDevice().Key = -1
return true
})
}
|
go
|
func EthernetCardTypes() VirtualDeviceList {
return VirtualDeviceList([]types.BaseVirtualDevice{
&types.VirtualE1000{},
&types.VirtualE1000e{},
&types.VirtualVmxnet2{},
&types.VirtualVmxnet3{},
&types.VirtualPCNet32{},
&types.VirtualSriovEthernetCard{},
}).Select(func(device types.BaseVirtualDevice) bool {
c := device.(types.BaseVirtualEthernetCard).GetVirtualEthernetCard()
c.GetVirtualDevice().Key = -1
return true
})
}
|
[
"func",
"EthernetCardTypes",
"(",
")",
"VirtualDeviceList",
"{",
"return",
"VirtualDeviceList",
"(",
"[",
"]",
"types",
".",
"BaseVirtualDevice",
"{",
"&",
"types",
".",
"VirtualE1000",
"{",
"}",
",",
"&",
"types",
".",
"VirtualE1000e",
"{",
"}",
",",
"&",
"types",
".",
"VirtualVmxnet2",
"{",
"}",
",",
"&",
"types",
".",
"VirtualVmxnet3",
"{",
"}",
",",
"&",
"types",
".",
"VirtualPCNet32",
"{",
"}",
",",
"&",
"types",
".",
"VirtualSriovEthernetCard",
"{",
"}",
",",
"}",
")",
".",
"Select",
"(",
"func",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"bool",
"{",
"c",
":=",
"device",
".",
"(",
"types",
".",
"BaseVirtualEthernetCard",
")",
".",
"GetVirtualEthernetCard",
"(",
")",
"\n",
"c",
".",
"GetVirtualDevice",
"(",
")",
".",
"Key",
"=",
"-",
"1",
"\n",
"return",
"true",
"\n",
"}",
")",
"\n",
"}"
] |
// EthernetCardTypes are used for adding a new ethernet card to a VM.
|
[
"EthernetCardTypes",
"are",
"used",
"for",
"adding",
"a",
"new",
"ethernet",
"card",
"to",
"a",
"VM",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L60-L73
|
21,234
|
vmware/govmomi
|
object/virtual_device_list.go
|
Select
|
func (l VirtualDeviceList) Select(f func(device types.BaseVirtualDevice) bool) VirtualDeviceList {
var found VirtualDeviceList
for _, device := range l {
if f(device) {
found = append(found, device)
}
}
return found
}
|
go
|
func (l VirtualDeviceList) Select(f func(device types.BaseVirtualDevice) bool) VirtualDeviceList {
var found VirtualDeviceList
for _, device := range l {
if f(device) {
found = append(found, device)
}
}
return found
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"Select",
"(",
"f",
"func",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"bool",
")",
"VirtualDeviceList",
"{",
"var",
"found",
"VirtualDeviceList",
"\n\n",
"for",
"_",
",",
"device",
":=",
"range",
"l",
"{",
"if",
"f",
"(",
"device",
")",
"{",
"found",
"=",
"append",
"(",
"found",
",",
"device",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"found",
"\n",
"}"
] |
// Select returns a new list containing all elements of the list for which the given func returns true.
|
[
"Select",
"returns",
"a",
"new",
"list",
"containing",
"all",
"elements",
"of",
"the",
"list",
"for",
"which",
"the",
"given",
"func",
"returns",
"true",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L76-L86
|
21,235
|
vmware/govmomi
|
object/virtual_device_list.go
|
SelectByType
|
func (l VirtualDeviceList) SelectByType(deviceType types.BaseVirtualDevice) VirtualDeviceList {
dtype := reflect.TypeOf(deviceType)
if dtype == nil {
return nil
}
dname := dtype.Elem().Name()
return l.Select(func(device types.BaseVirtualDevice) bool {
t := reflect.TypeOf(device)
if t == dtype {
return true
}
_, ok := t.Elem().FieldByName(dname)
return ok
})
}
|
go
|
func (l VirtualDeviceList) SelectByType(deviceType types.BaseVirtualDevice) VirtualDeviceList {
dtype := reflect.TypeOf(deviceType)
if dtype == nil {
return nil
}
dname := dtype.Elem().Name()
return l.Select(func(device types.BaseVirtualDevice) bool {
t := reflect.TypeOf(device)
if t == dtype {
return true
}
_, ok := t.Elem().FieldByName(dname)
return ok
})
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"SelectByType",
"(",
"deviceType",
"types",
".",
"BaseVirtualDevice",
")",
"VirtualDeviceList",
"{",
"dtype",
":=",
"reflect",
".",
"TypeOf",
"(",
"deviceType",
")",
"\n",
"if",
"dtype",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"dname",
":=",
"dtype",
".",
"Elem",
"(",
")",
".",
"Name",
"(",
")",
"\n\n",
"return",
"l",
".",
"Select",
"(",
"func",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"bool",
"{",
"t",
":=",
"reflect",
".",
"TypeOf",
"(",
"device",
")",
"\n\n",
"if",
"t",
"==",
"dtype",
"{",
"return",
"true",
"\n",
"}",
"\n\n",
"_",
",",
"ok",
":=",
"t",
".",
"Elem",
"(",
")",
".",
"FieldByName",
"(",
"dname",
")",
"\n\n",
"return",
"ok",
"\n",
"}",
")",
"\n",
"}"
] |
// SelectByType returns a new list with devices that are equal to or extend the given type.
|
[
"SelectByType",
"returns",
"a",
"new",
"list",
"with",
"devices",
"that",
"are",
"equal",
"to",
"or",
"extend",
"the",
"given",
"type",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L89-L107
|
21,236
|
vmware/govmomi
|
object/virtual_device_list.go
|
SelectByBackingInfo
|
func (l VirtualDeviceList) SelectByBackingInfo(backing types.BaseVirtualDeviceBackingInfo) VirtualDeviceList {
t := reflect.TypeOf(backing)
return l.Select(func(device types.BaseVirtualDevice) bool {
db := device.GetVirtualDevice().Backing
if db == nil {
return false
}
if reflect.TypeOf(db) != t {
return false
}
if reflect.ValueOf(backing).IsNil() {
// selecting by backing type
return true
}
switch a := db.(type) {
case *types.VirtualEthernetCardNetworkBackingInfo:
b := backing.(*types.VirtualEthernetCardNetworkBackingInfo)
return a.DeviceName == b.DeviceName
case *types.VirtualEthernetCardDistributedVirtualPortBackingInfo:
b := backing.(*types.VirtualEthernetCardDistributedVirtualPortBackingInfo)
return a.Port.SwitchUuid == b.Port.SwitchUuid &&
a.Port.PortgroupKey == b.Port.PortgroupKey
case *types.VirtualDiskFlatVer2BackingInfo:
b := backing.(*types.VirtualDiskFlatVer2BackingInfo)
if a.Parent != nil && b.Parent != nil {
return a.Parent.FileName == b.Parent.FileName
}
return a.FileName == b.FileName
case *types.VirtualSerialPortURIBackingInfo:
b := backing.(*types.VirtualSerialPortURIBackingInfo)
return a.ServiceURI == b.ServiceURI
case types.BaseVirtualDeviceFileBackingInfo:
b := backing.(types.BaseVirtualDeviceFileBackingInfo)
return a.GetVirtualDeviceFileBackingInfo().FileName == b.GetVirtualDeviceFileBackingInfo().FileName
default:
return false
}
})
}
|
go
|
func (l VirtualDeviceList) SelectByBackingInfo(backing types.BaseVirtualDeviceBackingInfo) VirtualDeviceList {
t := reflect.TypeOf(backing)
return l.Select(func(device types.BaseVirtualDevice) bool {
db := device.GetVirtualDevice().Backing
if db == nil {
return false
}
if reflect.TypeOf(db) != t {
return false
}
if reflect.ValueOf(backing).IsNil() {
// selecting by backing type
return true
}
switch a := db.(type) {
case *types.VirtualEthernetCardNetworkBackingInfo:
b := backing.(*types.VirtualEthernetCardNetworkBackingInfo)
return a.DeviceName == b.DeviceName
case *types.VirtualEthernetCardDistributedVirtualPortBackingInfo:
b := backing.(*types.VirtualEthernetCardDistributedVirtualPortBackingInfo)
return a.Port.SwitchUuid == b.Port.SwitchUuid &&
a.Port.PortgroupKey == b.Port.PortgroupKey
case *types.VirtualDiskFlatVer2BackingInfo:
b := backing.(*types.VirtualDiskFlatVer2BackingInfo)
if a.Parent != nil && b.Parent != nil {
return a.Parent.FileName == b.Parent.FileName
}
return a.FileName == b.FileName
case *types.VirtualSerialPortURIBackingInfo:
b := backing.(*types.VirtualSerialPortURIBackingInfo)
return a.ServiceURI == b.ServiceURI
case types.BaseVirtualDeviceFileBackingInfo:
b := backing.(types.BaseVirtualDeviceFileBackingInfo)
return a.GetVirtualDeviceFileBackingInfo().FileName == b.GetVirtualDeviceFileBackingInfo().FileName
default:
return false
}
})
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"SelectByBackingInfo",
"(",
"backing",
"types",
".",
"BaseVirtualDeviceBackingInfo",
")",
"VirtualDeviceList",
"{",
"t",
":=",
"reflect",
".",
"TypeOf",
"(",
"backing",
")",
"\n\n",
"return",
"l",
".",
"Select",
"(",
"func",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"bool",
"{",
"db",
":=",
"device",
".",
"GetVirtualDevice",
"(",
")",
".",
"Backing",
"\n",
"if",
"db",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"reflect",
".",
"TypeOf",
"(",
"db",
")",
"!=",
"t",
"{",
"return",
"false",
"\n",
"}",
"\n\n",
"if",
"reflect",
".",
"ValueOf",
"(",
"backing",
")",
".",
"IsNil",
"(",
")",
"{",
"// selecting by backing type",
"return",
"true",
"\n",
"}",
"\n\n",
"switch",
"a",
":=",
"db",
".",
"(",
"type",
")",
"{",
"case",
"*",
"types",
".",
"VirtualEthernetCardNetworkBackingInfo",
":",
"b",
":=",
"backing",
".",
"(",
"*",
"types",
".",
"VirtualEthernetCardNetworkBackingInfo",
")",
"\n",
"return",
"a",
".",
"DeviceName",
"==",
"b",
".",
"DeviceName",
"\n",
"case",
"*",
"types",
".",
"VirtualEthernetCardDistributedVirtualPortBackingInfo",
":",
"b",
":=",
"backing",
".",
"(",
"*",
"types",
".",
"VirtualEthernetCardDistributedVirtualPortBackingInfo",
")",
"\n",
"return",
"a",
".",
"Port",
".",
"SwitchUuid",
"==",
"b",
".",
"Port",
".",
"SwitchUuid",
"&&",
"a",
".",
"Port",
".",
"PortgroupKey",
"==",
"b",
".",
"Port",
".",
"PortgroupKey",
"\n",
"case",
"*",
"types",
".",
"VirtualDiskFlatVer2BackingInfo",
":",
"b",
":=",
"backing",
".",
"(",
"*",
"types",
".",
"VirtualDiskFlatVer2BackingInfo",
")",
"\n",
"if",
"a",
".",
"Parent",
"!=",
"nil",
"&&",
"b",
".",
"Parent",
"!=",
"nil",
"{",
"return",
"a",
".",
"Parent",
".",
"FileName",
"==",
"b",
".",
"Parent",
".",
"FileName",
"\n",
"}",
"\n",
"return",
"a",
".",
"FileName",
"==",
"b",
".",
"FileName",
"\n",
"case",
"*",
"types",
".",
"VirtualSerialPortURIBackingInfo",
":",
"b",
":=",
"backing",
".",
"(",
"*",
"types",
".",
"VirtualSerialPortURIBackingInfo",
")",
"\n",
"return",
"a",
".",
"ServiceURI",
"==",
"b",
".",
"ServiceURI",
"\n",
"case",
"types",
".",
"BaseVirtualDeviceFileBackingInfo",
":",
"b",
":=",
"backing",
".",
"(",
"types",
".",
"BaseVirtualDeviceFileBackingInfo",
")",
"\n",
"return",
"a",
".",
"GetVirtualDeviceFileBackingInfo",
"(",
")",
".",
"FileName",
"==",
"b",
".",
"GetVirtualDeviceFileBackingInfo",
"(",
")",
".",
"FileName",
"\n",
"default",
":",
"return",
"false",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] |
// SelectByBackingInfo returns a new list with devices matching the given backing info.
// If the value of backing is nil, any device with a backing of the same type will be returned.
|
[
"SelectByBackingInfo",
"returns",
"a",
"new",
"list",
"with",
"devices",
"matching",
"the",
"given",
"backing",
"info",
".",
"If",
"the",
"value",
"of",
"backing",
"is",
"nil",
"any",
"device",
"with",
"a",
"backing",
"of",
"the",
"same",
"type",
"will",
"be",
"returned",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L111-L153
|
21,237
|
vmware/govmomi
|
object/virtual_device_list.go
|
Find
|
func (l VirtualDeviceList) Find(name string) types.BaseVirtualDevice {
for _, device := range l {
if l.Name(device) == name {
return device
}
}
return nil
}
|
go
|
func (l VirtualDeviceList) Find(name string) types.BaseVirtualDevice {
for _, device := range l {
if l.Name(device) == name {
return device
}
}
return nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"Find",
"(",
"name",
"string",
")",
"types",
".",
"BaseVirtualDevice",
"{",
"for",
"_",
",",
"device",
":=",
"range",
"l",
"{",
"if",
"l",
".",
"Name",
"(",
"device",
")",
"==",
"name",
"{",
"return",
"device",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Find returns the device matching the given name.
|
[
"Find",
"returns",
"the",
"device",
"matching",
"the",
"given",
"name",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L156-L163
|
21,238
|
vmware/govmomi
|
object/virtual_device_list.go
|
FindByKey
|
func (l VirtualDeviceList) FindByKey(key int32) types.BaseVirtualDevice {
for _, device := range l {
if device.GetVirtualDevice().Key == key {
return device
}
}
return nil
}
|
go
|
func (l VirtualDeviceList) FindByKey(key int32) types.BaseVirtualDevice {
for _, device := range l {
if device.GetVirtualDevice().Key == key {
return device
}
}
return nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"FindByKey",
"(",
"key",
"int32",
")",
"types",
".",
"BaseVirtualDevice",
"{",
"for",
"_",
",",
"device",
":=",
"range",
"l",
"{",
"if",
"device",
".",
"GetVirtualDevice",
"(",
")",
".",
"Key",
"==",
"key",
"{",
"return",
"device",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// FindByKey returns the device matching the given key.
|
[
"FindByKey",
"returns",
"the",
"device",
"matching",
"the",
"given",
"key",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L166-L173
|
21,239
|
vmware/govmomi
|
object/virtual_device_list.go
|
FindIDEController
|
func (l VirtualDeviceList) FindIDEController(name string) (*types.VirtualIDEController, error) {
if name != "" {
d := l.Find(name)
if d == nil {
return nil, fmt.Errorf("device '%s' not found", name)
}
if c, ok := d.(*types.VirtualIDEController); ok {
return c, nil
}
return nil, fmt.Errorf("%s is not an IDE controller", name)
}
c := l.PickController((*types.VirtualIDEController)(nil))
if c == nil {
return nil, errors.New("no available IDE controller")
}
return c.(*types.VirtualIDEController), nil
}
|
go
|
func (l VirtualDeviceList) FindIDEController(name string) (*types.VirtualIDEController, error) {
if name != "" {
d := l.Find(name)
if d == nil {
return nil, fmt.Errorf("device '%s' not found", name)
}
if c, ok := d.(*types.VirtualIDEController); ok {
return c, nil
}
return nil, fmt.Errorf("%s is not an IDE controller", name)
}
c := l.PickController((*types.VirtualIDEController)(nil))
if c == nil {
return nil, errors.New("no available IDE controller")
}
return c.(*types.VirtualIDEController), nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"FindIDEController",
"(",
"name",
"string",
")",
"(",
"*",
"types",
".",
"VirtualIDEController",
",",
"error",
")",
"{",
"if",
"name",
"!=",
"\"",
"\"",
"{",
"d",
":=",
"l",
".",
"Find",
"(",
"name",
")",
"\n",
"if",
"d",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"if",
"c",
",",
"ok",
":=",
"d",
".",
"(",
"*",
"types",
".",
"VirtualIDEController",
")",
";",
"ok",
"{",
"return",
"c",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"c",
":=",
"l",
".",
"PickController",
"(",
"(",
"*",
"types",
".",
"VirtualIDEController",
")",
"(",
"nil",
")",
")",
"\n",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"(",
"*",
"types",
".",
"VirtualIDEController",
")",
",",
"nil",
"\n",
"}"
] |
// FindIDEController will find the named IDE controller if given, otherwise will pick an available controller.
// An error is returned if the named controller is not found or not an IDE controller. Or, if name is not
// given and no available controller can be found.
|
[
"FindIDEController",
"will",
"find",
"the",
"named",
"IDE",
"controller",
"if",
"given",
"otherwise",
"will",
"pick",
"an",
"available",
"controller",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"named",
"controller",
"is",
"not",
"found",
"or",
"not",
"an",
"IDE",
"controller",
".",
"Or",
"if",
"name",
"is",
"not",
"given",
"and",
"no",
"available",
"controller",
"can",
"be",
"found",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L178-L196
|
21,240
|
vmware/govmomi
|
object/virtual_device_list.go
|
CreateIDEController
|
func (l VirtualDeviceList) CreateIDEController() (types.BaseVirtualDevice, error) {
ide := &types.VirtualIDEController{}
ide.Key = l.NewKey()
return ide, nil
}
|
go
|
func (l VirtualDeviceList) CreateIDEController() (types.BaseVirtualDevice, error) {
ide := &types.VirtualIDEController{}
ide.Key = l.NewKey()
return ide, nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"CreateIDEController",
"(",
")",
"(",
"types",
".",
"BaseVirtualDevice",
",",
"error",
")",
"{",
"ide",
":=",
"&",
"types",
".",
"VirtualIDEController",
"{",
"}",
"\n",
"ide",
".",
"Key",
"=",
"l",
".",
"NewKey",
"(",
")",
"\n",
"return",
"ide",
",",
"nil",
"\n",
"}"
] |
// CreateIDEController creates a new IDE controller.
|
[
"CreateIDEController",
"creates",
"a",
"new",
"IDE",
"controller",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L199-L203
|
21,241
|
vmware/govmomi
|
object/virtual_device_list.go
|
FindSCSIController
|
func (l VirtualDeviceList) FindSCSIController(name string) (*types.VirtualSCSIController, error) {
if name != "" {
d := l.Find(name)
if d == nil {
return nil, fmt.Errorf("device '%s' not found", name)
}
if c, ok := d.(types.BaseVirtualSCSIController); ok {
return c.GetVirtualSCSIController(), nil
}
return nil, fmt.Errorf("%s is not an SCSI controller", name)
}
c := l.PickController((*types.VirtualSCSIController)(nil))
if c == nil {
return nil, errors.New("no available SCSI controller")
}
return c.(types.BaseVirtualSCSIController).GetVirtualSCSIController(), nil
}
|
go
|
func (l VirtualDeviceList) FindSCSIController(name string) (*types.VirtualSCSIController, error) {
if name != "" {
d := l.Find(name)
if d == nil {
return nil, fmt.Errorf("device '%s' not found", name)
}
if c, ok := d.(types.BaseVirtualSCSIController); ok {
return c.GetVirtualSCSIController(), nil
}
return nil, fmt.Errorf("%s is not an SCSI controller", name)
}
c := l.PickController((*types.VirtualSCSIController)(nil))
if c == nil {
return nil, errors.New("no available SCSI controller")
}
return c.(types.BaseVirtualSCSIController).GetVirtualSCSIController(), nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"FindSCSIController",
"(",
"name",
"string",
")",
"(",
"*",
"types",
".",
"VirtualSCSIController",
",",
"error",
")",
"{",
"if",
"name",
"!=",
"\"",
"\"",
"{",
"d",
":=",
"l",
".",
"Find",
"(",
"name",
")",
"\n",
"if",
"d",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"if",
"c",
",",
"ok",
":=",
"d",
".",
"(",
"types",
".",
"BaseVirtualSCSIController",
")",
";",
"ok",
"{",
"return",
"c",
".",
"GetVirtualSCSIController",
"(",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"c",
":=",
"l",
".",
"PickController",
"(",
"(",
"*",
"types",
".",
"VirtualSCSIController",
")",
"(",
"nil",
")",
")",
"\n",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"(",
"types",
".",
"BaseVirtualSCSIController",
")",
".",
"GetVirtualSCSIController",
"(",
")",
",",
"nil",
"\n",
"}"
] |
// FindSCSIController will find the named SCSI controller if given, otherwise will pick an available controller.
// An error is returned if the named controller is not found or not an SCSI controller. Or, if name is not
// given and no available controller can be found.
|
[
"FindSCSIController",
"will",
"find",
"the",
"named",
"SCSI",
"controller",
"if",
"given",
"otherwise",
"will",
"pick",
"an",
"available",
"controller",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"named",
"controller",
"is",
"not",
"found",
"or",
"not",
"an",
"SCSI",
"controller",
".",
"Or",
"if",
"name",
"is",
"not",
"given",
"and",
"no",
"available",
"controller",
"can",
"be",
"found",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L208-L226
|
21,242
|
vmware/govmomi
|
object/virtual_device_list.go
|
CreateSCSIController
|
func (l VirtualDeviceList) CreateSCSIController(name string) (types.BaseVirtualDevice, error) {
ctypes := SCSIControllerTypes()
if name == "" || name == "scsi" {
name = ctypes.Type(ctypes[0])
} else if name == "virtualscsi" {
name = "pvscsi" // ovf VirtualSCSI mapping
}
found := ctypes.Select(func(device types.BaseVirtualDevice) bool {
return l.Type(device) == name
})
if len(found) == 0 {
return nil, fmt.Errorf("unknown SCSI controller type '%s'", name)
}
c, ok := found[0].(types.BaseVirtualSCSIController)
if !ok {
return nil, fmt.Errorf("invalid SCSI controller type '%s'", name)
}
scsi := c.GetVirtualSCSIController()
scsi.BusNumber = l.newSCSIBusNumber()
scsi.Key = l.NewKey()
scsi.ScsiCtlrUnitNumber = 7
return c.(types.BaseVirtualDevice), nil
}
|
go
|
func (l VirtualDeviceList) CreateSCSIController(name string) (types.BaseVirtualDevice, error) {
ctypes := SCSIControllerTypes()
if name == "" || name == "scsi" {
name = ctypes.Type(ctypes[0])
} else if name == "virtualscsi" {
name = "pvscsi" // ovf VirtualSCSI mapping
}
found := ctypes.Select(func(device types.BaseVirtualDevice) bool {
return l.Type(device) == name
})
if len(found) == 0 {
return nil, fmt.Errorf("unknown SCSI controller type '%s'", name)
}
c, ok := found[0].(types.BaseVirtualSCSIController)
if !ok {
return nil, fmt.Errorf("invalid SCSI controller type '%s'", name)
}
scsi := c.GetVirtualSCSIController()
scsi.BusNumber = l.newSCSIBusNumber()
scsi.Key = l.NewKey()
scsi.ScsiCtlrUnitNumber = 7
return c.(types.BaseVirtualDevice), nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"CreateSCSIController",
"(",
"name",
"string",
")",
"(",
"types",
".",
"BaseVirtualDevice",
",",
"error",
")",
"{",
"ctypes",
":=",
"SCSIControllerTypes",
"(",
")",
"\n\n",
"if",
"name",
"==",
"\"",
"\"",
"||",
"name",
"==",
"\"",
"\"",
"{",
"name",
"=",
"ctypes",
".",
"Type",
"(",
"ctypes",
"[",
"0",
"]",
")",
"\n",
"}",
"else",
"if",
"name",
"==",
"\"",
"\"",
"{",
"name",
"=",
"\"",
"\"",
"// ovf VirtualSCSI mapping",
"\n",
"}",
"\n\n",
"found",
":=",
"ctypes",
".",
"Select",
"(",
"func",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"bool",
"{",
"return",
"l",
".",
"Type",
"(",
"device",
")",
"==",
"name",
"\n",
"}",
")",
"\n\n",
"if",
"len",
"(",
"found",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"c",
",",
"ok",
":=",
"found",
"[",
"0",
"]",
".",
"(",
"types",
".",
"BaseVirtualSCSIController",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"scsi",
":=",
"c",
".",
"GetVirtualSCSIController",
"(",
")",
"\n",
"scsi",
".",
"BusNumber",
"=",
"l",
".",
"newSCSIBusNumber",
"(",
")",
"\n",
"scsi",
".",
"Key",
"=",
"l",
".",
"NewKey",
"(",
")",
"\n",
"scsi",
".",
"ScsiCtlrUnitNumber",
"=",
"7",
"\n",
"return",
"c",
".",
"(",
"types",
".",
"BaseVirtualDevice",
")",
",",
"nil",
"\n",
"}"
] |
// CreateSCSIController creates a new SCSI controller of type name if given, otherwise defaults to lsilogic.
|
[
"CreateSCSIController",
"creates",
"a",
"new",
"SCSI",
"controller",
"of",
"type",
"name",
"if",
"given",
"otherwise",
"defaults",
"to",
"lsilogic",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L229-L256
|
21,243
|
vmware/govmomi
|
object/virtual_device_list.go
|
newSCSIBusNumber
|
func (l VirtualDeviceList) newSCSIBusNumber() int32 {
var used []int
for _, d := range l.SelectByType((*types.VirtualSCSIController)(nil)) {
num := d.(types.BaseVirtualSCSIController).GetVirtualSCSIController().BusNumber
if num >= 0 {
used = append(used, int(num))
} // else caller is creating a new vm using SCSIControllerTypes
}
sort.Ints(used)
for i, n := range scsiBusNumbers {
if i == len(used) || n != used[i] {
return int32(n)
}
}
return -1
}
|
go
|
func (l VirtualDeviceList) newSCSIBusNumber() int32 {
var used []int
for _, d := range l.SelectByType((*types.VirtualSCSIController)(nil)) {
num := d.(types.BaseVirtualSCSIController).GetVirtualSCSIController().BusNumber
if num >= 0 {
used = append(used, int(num))
} // else caller is creating a new vm using SCSIControllerTypes
}
sort.Ints(used)
for i, n := range scsiBusNumbers {
if i == len(used) || n != used[i] {
return int32(n)
}
}
return -1
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"newSCSIBusNumber",
"(",
")",
"int32",
"{",
"var",
"used",
"[",
"]",
"int",
"\n\n",
"for",
"_",
",",
"d",
":=",
"range",
"l",
".",
"SelectByType",
"(",
"(",
"*",
"types",
".",
"VirtualSCSIController",
")",
"(",
"nil",
")",
")",
"{",
"num",
":=",
"d",
".",
"(",
"types",
".",
"BaseVirtualSCSIController",
")",
".",
"GetVirtualSCSIController",
"(",
")",
".",
"BusNumber",
"\n",
"if",
"num",
">=",
"0",
"{",
"used",
"=",
"append",
"(",
"used",
",",
"int",
"(",
"num",
")",
")",
"\n",
"}",
"// else caller is creating a new vm using SCSIControllerTypes",
"\n",
"}",
"\n\n",
"sort",
".",
"Ints",
"(",
"used",
")",
"\n\n",
"for",
"i",
",",
"n",
":=",
"range",
"scsiBusNumbers",
"{",
"if",
"i",
"==",
"len",
"(",
"used",
")",
"||",
"n",
"!=",
"used",
"[",
"i",
"]",
"{",
"return",
"int32",
"(",
"n",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"-",
"1",
"\n",
"}"
] |
// newSCSIBusNumber returns the bus number to use for adding a new SCSI bus device.
// -1 is returned if there are no bus numbers available.
|
[
"newSCSIBusNumber",
"returns",
"the",
"bus",
"number",
"to",
"use",
"for",
"adding",
"a",
"new",
"SCSI",
"bus",
"device",
".",
"-",
"1",
"is",
"returned",
"if",
"there",
"are",
"no",
"bus",
"numbers",
"available",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L262-L281
|
21,244
|
vmware/govmomi
|
object/virtual_device_list.go
|
CreateNVMEController
|
func (l VirtualDeviceList) CreateNVMEController() (types.BaseVirtualDevice, error) {
nvme := &types.VirtualNVMEController{}
nvme.BusNumber = l.newNVMEBusNumber()
nvme.Key = l.NewKey()
return nvme, nil
}
|
go
|
func (l VirtualDeviceList) CreateNVMEController() (types.BaseVirtualDevice, error) {
nvme := &types.VirtualNVMEController{}
nvme.BusNumber = l.newNVMEBusNumber()
nvme.Key = l.NewKey()
return nvme, nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"CreateNVMEController",
"(",
")",
"(",
"types",
".",
"BaseVirtualDevice",
",",
"error",
")",
"{",
"nvme",
":=",
"&",
"types",
".",
"VirtualNVMEController",
"{",
"}",
"\n",
"nvme",
".",
"BusNumber",
"=",
"l",
".",
"newNVMEBusNumber",
"(",
")",
"\n",
"nvme",
".",
"Key",
"=",
"l",
".",
"NewKey",
"(",
")",
"\n\n",
"return",
"nvme",
",",
"nil",
"\n",
"}"
] |
// CreateNVMEController creates a new NVMWE controller.
|
[
"CreateNVMEController",
"creates",
"a",
"new",
"NVMWE",
"controller",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L307-L313
|
21,245
|
vmware/govmomi
|
object/virtual_device_list.go
|
newNVMEBusNumber
|
func (l VirtualDeviceList) newNVMEBusNumber() int32 {
var used []int
for _, d := range l.SelectByType((*types.VirtualNVMEController)(nil)) {
num := d.(types.BaseVirtualController).GetVirtualController().BusNumber
if num >= 0 {
used = append(used, int(num))
} // else caller is creating a new vm using NVMEControllerTypes
}
sort.Ints(used)
for i, n := range nvmeBusNumbers {
if i == len(used) || n != used[i] {
return int32(n)
}
}
return -1
}
|
go
|
func (l VirtualDeviceList) newNVMEBusNumber() int32 {
var used []int
for _, d := range l.SelectByType((*types.VirtualNVMEController)(nil)) {
num := d.(types.BaseVirtualController).GetVirtualController().BusNumber
if num >= 0 {
used = append(used, int(num))
} // else caller is creating a new vm using NVMEControllerTypes
}
sort.Ints(used)
for i, n := range nvmeBusNumbers {
if i == len(used) || n != used[i] {
return int32(n)
}
}
return -1
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"newNVMEBusNumber",
"(",
")",
"int32",
"{",
"var",
"used",
"[",
"]",
"int",
"\n\n",
"for",
"_",
",",
"d",
":=",
"range",
"l",
".",
"SelectByType",
"(",
"(",
"*",
"types",
".",
"VirtualNVMEController",
")",
"(",
"nil",
")",
")",
"{",
"num",
":=",
"d",
".",
"(",
"types",
".",
"BaseVirtualController",
")",
".",
"GetVirtualController",
"(",
")",
".",
"BusNumber",
"\n",
"if",
"num",
">=",
"0",
"{",
"used",
"=",
"append",
"(",
"used",
",",
"int",
"(",
"num",
")",
")",
"\n",
"}",
"// else caller is creating a new vm using NVMEControllerTypes",
"\n",
"}",
"\n\n",
"sort",
".",
"Ints",
"(",
"used",
")",
"\n\n",
"for",
"i",
",",
"n",
":=",
"range",
"nvmeBusNumbers",
"{",
"if",
"i",
"==",
"len",
"(",
"used",
")",
"||",
"n",
"!=",
"used",
"[",
"i",
"]",
"{",
"return",
"int32",
"(",
"n",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"-",
"1",
"\n",
"}"
] |
// newNVMEBusNumber returns the bus number to use for adding a new NVME bus device.
// -1 is returned if there are no bus numbers available.
|
[
"newNVMEBusNumber",
"returns",
"the",
"bus",
"number",
"to",
"use",
"for",
"adding",
"a",
"new",
"NVME",
"bus",
"device",
".",
"-",
"1",
"is",
"returned",
"if",
"there",
"are",
"no",
"bus",
"numbers",
"available",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L319-L338
|
21,246
|
vmware/govmomi
|
object/virtual_device_list.go
|
FindDiskController
|
func (l VirtualDeviceList) FindDiskController(name string) (types.BaseVirtualController, error) {
switch {
case name == "ide":
return l.FindIDEController("")
case name == "scsi" || name == "":
return l.FindSCSIController("")
case name == "nvme":
return l.FindNVMEController("")
default:
if c, ok := l.Find(name).(types.BaseVirtualController); ok {
return c, nil
}
return nil, fmt.Errorf("%s is not a valid controller", name)
}
}
|
go
|
func (l VirtualDeviceList) FindDiskController(name string) (types.BaseVirtualController, error) {
switch {
case name == "ide":
return l.FindIDEController("")
case name == "scsi" || name == "":
return l.FindSCSIController("")
case name == "nvme":
return l.FindNVMEController("")
default:
if c, ok := l.Find(name).(types.BaseVirtualController); ok {
return c, nil
}
return nil, fmt.Errorf("%s is not a valid controller", name)
}
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"FindDiskController",
"(",
"name",
"string",
")",
"(",
"types",
".",
"BaseVirtualController",
",",
"error",
")",
"{",
"switch",
"{",
"case",
"name",
"==",
"\"",
"\"",
":",
"return",
"l",
".",
"FindIDEController",
"(",
"\"",
"\"",
")",
"\n",
"case",
"name",
"==",
"\"",
"\"",
"||",
"name",
"==",
"\"",
"\"",
":",
"return",
"l",
".",
"FindSCSIController",
"(",
"\"",
"\"",
")",
"\n",
"case",
"name",
"==",
"\"",
"\"",
":",
"return",
"l",
".",
"FindNVMEController",
"(",
"\"",
"\"",
")",
"\n",
"default",
":",
"if",
"c",
",",
"ok",
":=",
"l",
".",
"Find",
"(",
"name",
")",
".",
"(",
"types",
".",
"BaseVirtualController",
")",
";",
"ok",
"{",
"return",
"c",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"}"
] |
// FindDiskController will find an existing ide or scsi disk controller.
|
[
"FindDiskController",
"will",
"find",
"an",
"existing",
"ide",
"or",
"scsi",
"disk",
"controller",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L341-L355
|
21,247
|
vmware/govmomi
|
object/virtual_device_list.go
|
newUnitNumber
|
func (l VirtualDeviceList) newUnitNumber(c types.BaseVirtualController) int32 {
units := make([]bool, 30)
switch sc := c.(type) {
case types.BaseVirtualSCSIController:
// The SCSI controller sits on its own bus
units[sc.GetVirtualSCSIController().ScsiCtlrUnitNumber] = true
}
key := c.GetVirtualController().Key
for _, device := range l {
d := device.GetVirtualDevice()
if d.ControllerKey == key && d.UnitNumber != nil {
units[int(*d.UnitNumber)] = true
}
}
for unit, used := range units {
if !used {
return int32(unit)
}
}
return -1
}
|
go
|
func (l VirtualDeviceList) newUnitNumber(c types.BaseVirtualController) int32 {
units := make([]bool, 30)
switch sc := c.(type) {
case types.BaseVirtualSCSIController:
// The SCSI controller sits on its own bus
units[sc.GetVirtualSCSIController().ScsiCtlrUnitNumber] = true
}
key := c.GetVirtualController().Key
for _, device := range l {
d := device.GetVirtualDevice()
if d.ControllerKey == key && d.UnitNumber != nil {
units[int(*d.UnitNumber)] = true
}
}
for unit, used := range units {
if !used {
return int32(unit)
}
}
return -1
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"newUnitNumber",
"(",
"c",
"types",
".",
"BaseVirtualController",
")",
"int32",
"{",
"units",
":=",
"make",
"(",
"[",
"]",
"bool",
",",
"30",
")",
"\n\n",
"switch",
"sc",
":=",
"c",
".",
"(",
"type",
")",
"{",
"case",
"types",
".",
"BaseVirtualSCSIController",
":",
"// The SCSI controller sits on its own bus",
"units",
"[",
"sc",
".",
"GetVirtualSCSIController",
"(",
")",
".",
"ScsiCtlrUnitNumber",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"key",
":=",
"c",
".",
"GetVirtualController",
"(",
")",
".",
"Key",
"\n\n",
"for",
"_",
",",
"device",
":=",
"range",
"l",
"{",
"d",
":=",
"device",
".",
"GetVirtualDevice",
"(",
")",
"\n\n",
"if",
"d",
".",
"ControllerKey",
"==",
"key",
"&&",
"d",
".",
"UnitNumber",
"!=",
"nil",
"{",
"units",
"[",
"int",
"(",
"*",
"d",
".",
"UnitNumber",
")",
"]",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"unit",
",",
"used",
":=",
"range",
"units",
"{",
"if",
"!",
"used",
"{",
"return",
"int32",
"(",
"unit",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"-",
"1",
"\n",
"}"
] |
// newUnitNumber returns the unit number to use for attaching a new device to the given controller.
|
[
"newUnitNumber",
"returns",
"the",
"unit",
"number",
"to",
"use",
"for",
"attaching",
"a",
"new",
"device",
"to",
"the",
"given",
"controller",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L383-L409
|
21,248
|
vmware/govmomi
|
object/virtual_device_list.go
|
AssignController
|
func (l VirtualDeviceList) AssignController(device types.BaseVirtualDevice, c types.BaseVirtualController) {
d := device.GetVirtualDevice()
d.ControllerKey = c.GetVirtualController().Key
d.UnitNumber = new(int32)
*d.UnitNumber = l.newUnitNumber(c)
if d.Key == 0 {
d.Key = -1
}
}
|
go
|
func (l VirtualDeviceList) AssignController(device types.BaseVirtualDevice, c types.BaseVirtualController) {
d := device.GetVirtualDevice()
d.ControllerKey = c.GetVirtualController().Key
d.UnitNumber = new(int32)
*d.UnitNumber = l.newUnitNumber(c)
if d.Key == 0 {
d.Key = -1
}
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"AssignController",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
",",
"c",
"types",
".",
"BaseVirtualController",
")",
"{",
"d",
":=",
"device",
".",
"GetVirtualDevice",
"(",
")",
"\n",
"d",
".",
"ControllerKey",
"=",
"c",
".",
"GetVirtualController",
"(",
")",
".",
"Key",
"\n",
"d",
".",
"UnitNumber",
"=",
"new",
"(",
"int32",
")",
"\n",
"*",
"d",
".",
"UnitNumber",
"=",
"l",
".",
"newUnitNumber",
"(",
"c",
")",
"\n",
"if",
"d",
".",
"Key",
"==",
"0",
"{",
"d",
".",
"Key",
"=",
"-",
"1",
"\n",
"}",
"\n",
"}"
] |
// AssignController assigns a device to a controller.
|
[
"AssignController",
"assigns",
"a",
"device",
"to",
"a",
"controller",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L430-L438
|
21,249
|
vmware/govmomi
|
object/virtual_device_list.go
|
CreateDisk
|
func (l VirtualDeviceList) CreateDisk(c types.BaseVirtualController, ds types.ManagedObjectReference, name string) *types.VirtualDisk {
// If name is not specified, one will be chosen for you.
// But if when given, make sure it ends in .vmdk, otherwise it will be treated as a directory.
if len(name) > 0 && filepath.Ext(name) != ".vmdk" {
name += ".vmdk"
}
device := &types.VirtualDisk{
VirtualDevice: types.VirtualDevice{
Backing: &types.VirtualDiskFlatVer2BackingInfo{
DiskMode: string(types.VirtualDiskModePersistent),
ThinProvisioned: types.NewBool(true),
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: name,
Datastore: &ds,
},
},
},
}
l.AssignController(device, c)
return device
}
|
go
|
func (l VirtualDeviceList) CreateDisk(c types.BaseVirtualController, ds types.ManagedObjectReference, name string) *types.VirtualDisk {
// If name is not specified, one will be chosen for you.
// But if when given, make sure it ends in .vmdk, otherwise it will be treated as a directory.
if len(name) > 0 && filepath.Ext(name) != ".vmdk" {
name += ".vmdk"
}
device := &types.VirtualDisk{
VirtualDevice: types.VirtualDevice{
Backing: &types.VirtualDiskFlatVer2BackingInfo{
DiskMode: string(types.VirtualDiskModePersistent),
ThinProvisioned: types.NewBool(true),
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: name,
Datastore: &ds,
},
},
},
}
l.AssignController(device, c)
return device
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"CreateDisk",
"(",
"c",
"types",
".",
"BaseVirtualController",
",",
"ds",
"types",
".",
"ManagedObjectReference",
",",
"name",
"string",
")",
"*",
"types",
".",
"VirtualDisk",
"{",
"// If name is not specified, one will be chosen for you.",
"// But if when given, make sure it ends in .vmdk, otherwise it will be treated as a directory.",
"if",
"len",
"(",
"name",
")",
">",
"0",
"&&",
"filepath",
".",
"Ext",
"(",
"name",
")",
"!=",
"\"",
"\"",
"{",
"name",
"+=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"device",
":=",
"&",
"types",
".",
"VirtualDisk",
"{",
"VirtualDevice",
":",
"types",
".",
"VirtualDevice",
"{",
"Backing",
":",
"&",
"types",
".",
"VirtualDiskFlatVer2BackingInfo",
"{",
"DiskMode",
":",
"string",
"(",
"types",
".",
"VirtualDiskModePersistent",
")",
",",
"ThinProvisioned",
":",
"types",
".",
"NewBool",
"(",
"true",
")",
",",
"VirtualDeviceFileBackingInfo",
":",
"types",
".",
"VirtualDeviceFileBackingInfo",
"{",
"FileName",
":",
"name",
",",
"Datastore",
":",
"&",
"ds",
",",
"}",
",",
"}",
",",
"}",
",",
"}",
"\n\n",
"l",
".",
"AssignController",
"(",
"device",
",",
"c",
")",
"\n",
"return",
"device",
"\n",
"}"
] |
// CreateDisk creates a new VirtualDisk device which can be added to a VM.
|
[
"CreateDisk",
"creates",
"a",
"new",
"VirtualDisk",
"device",
"which",
"can",
"be",
"added",
"to",
"a",
"VM",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L441-L463
|
21,250
|
vmware/govmomi
|
object/virtual_device_list.go
|
ChildDisk
|
func (l VirtualDeviceList) ChildDisk(parent *types.VirtualDisk) *types.VirtualDisk {
disk := *parent
backing := disk.Backing.(*types.VirtualDiskFlatVer2BackingInfo)
p := new(DatastorePath)
p.FromString(backing.FileName)
p.Path = ""
// Use specified disk as parent backing to a new disk.
disk.Backing = &types.VirtualDiskFlatVer2BackingInfo{
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: p.String(),
Datastore: backing.Datastore,
},
Parent: backing,
DiskMode: backing.DiskMode,
ThinProvisioned: backing.ThinProvisioned,
}
return &disk
}
|
go
|
func (l VirtualDeviceList) ChildDisk(parent *types.VirtualDisk) *types.VirtualDisk {
disk := *parent
backing := disk.Backing.(*types.VirtualDiskFlatVer2BackingInfo)
p := new(DatastorePath)
p.FromString(backing.FileName)
p.Path = ""
// Use specified disk as parent backing to a new disk.
disk.Backing = &types.VirtualDiskFlatVer2BackingInfo{
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: p.String(),
Datastore: backing.Datastore,
},
Parent: backing,
DiskMode: backing.DiskMode,
ThinProvisioned: backing.ThinProvisioned,
}
return &disk
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"ChildDisk",
"(",
"parent",
"*",
"types",
".",
"VirtualDisk",
")",
"*",
"types",
".",
"VirtualDisk",
"{",
"disk",
":=",
"*",
"parent",
"\n",
"backing",
":=",
"disk",
".",
"Backing",
".",
"(",
"*",
"types",
".",
"VirtualDiskFlatVer2BackingInfo",
")",
"\n",
"p",
":=",
"new",
"(",
"DatastorePath",
")",
"\n",
"p",
".",
"FromString",
"(",
"backing",
".",
"FileName",
")",
"\n",
"p",
".",
"Path",
"=",
"\"",
"\"",
"\n\n",
"// Use specified disk as parent backing to a new disk.",
"disk",
".",
"Backing",
"=",
"&",
"types",
".",
"VirtualDiskFlatVer2BackingInfo",
"{",
"VirtualDeviceFileBackingInfo",
":",
"types",
".",
"VirtualDeviceFileBackingInfo",
"{",
"FileName",
":",
"p",
".",
"String",
"(",
")",
",",
"Datastore",
":",
"backing",
".",
"Datastore",
",",
"}",
",",
"Parent",
":",
"backing",
",",
"DiskMode",
":",
"backing",
".",
"DiskMode",
",",
"ThinProvisioned",
":",
"backing",
".",
"ThinProvisioned",
",",
"}",
"\n\n",
"return",
"&",
"disk",
"\n",
"}"
] |
// ChildDisk creates a new VirtualDisk device, linked to the given parent disk, which can be added to a VM.
|
[
"ChildDisk",
"creates",
"a",
"new",
"VirtualDisk",
"device",
"linked",
"to",
"the",
"given",
"parent",
"disk",
"which",
"can",
"be",
"added",
"to",
"a",
"VM",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L466-L485
|
21,251
|
vmware/govmomi
|
object/virtual_device_list.go
|
Connect
|
func (l VirtualDeviceList) Connect(device types.BaseVirtualDevice) error {
return l.connectivity(device, true)
}
|
go
|
func (l VirtualDeviceList) Connect(device types.BaseVirtualDevice) error {
return l.connectivity(device, true)
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"Connect",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"error",
"{",
"return",
"l",
".",
"connectivity",
"(",
"device",
",",
"true",
")",
"\n",
"}"
] |
// Connect changes the device to connected, returns an error if the device is not connectable.
|
[
"Connect",
"changes",
"the",
"device",
"to",
"connected",
"returns",
"an",
"error",
"if",
"the",
"device",
"is",
"not",
"connectable",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L500-L502
|
21,252
|
vmware/govmomi
|
object/virtual_device_list.go
|
Disconnect
|
func (l VirtualDeviceList) Disconnect(device types.BaseVirtualDevice) error {
return l.connectivity(device, false)
}
|
go
|
func (l VirtualDeviceList) Disconnect(device types.BaseVirtualDevice) error {
return l.connectivity(device, false)
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"Disconnect",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"error",
"{",
"return",
"l",
".",
"connectivity",
"(",
"device",
",",
"false",
")",
"\n",
"}"
] |
// Disconnect changes the device to disconnected, returns an error if the device is not connectable.
|
[
"Disconnect",
"changes",
"the",
"device",
"to",
"disconnected",
"returns",
"an",
"error",
"if",
"the",
"device",
"is",
"not",
"connectable",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L505-L507
|
21,253
|
vmware/govmomi
|
object/virtual_device_list.go
|
FindCdrom
|
func (l VirtualDeviceList) FindCdrom(name string) (*types.VirtualCdrom, error) {
if name != "" {
d := l.Find(name)
if d == nil {
return nil, fmt.Errorf("device '%s' not found", name)
}
if c, ok := d.(*types.VirtualCdrom); ok {
return c, nil
}
return nil, fmt.Errorf("%s is not a cdrom device", name)
}
c := l.SelectByType((*types.VirtualCdrom)(nil))
if len(c) == 0 {
return nil, errors.New("no cdrom device found")
}
return c[0].(*types.VirtualCdrom), nil
}
|
go
|
func (l VirtualDeviceList) FindCdrom(name string) (*types.VirtualCdrom, error) {
if name != "" {
d := l.Find(name)
if d == nil {
return nil, fmt.Errorf("device '%s' not found", name)
}
if c, ok := d.(*types.VirtualCdrom); ok {
return c, nil
}
return nil, fmt.Errorf("%s is not a cdrom device", name)
}
c := l.SelectByType((*types.VirtualCdrom)(nil))
if len(c) == 0 {
return nil, errors.New("no cdrom device found")
}
return c[0].(*types.VirtualCdrom), nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"FindCdrom",
"(",
"name",
"string",
")",
"(",
"*",
"types",
".",
"VirtualCdrom",
",",
"error",
")",
"{",
"if",
"name",
"!=",
"\"",
"\"",
"{",
"d",
":=",
"l",
".",
"Find",
"(",
"name",
")",
"\n",
"if",
"d",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"if",
"c",
",",
"ok",
":=",
"d",
".",
"(",
"*",
"types",
".",
"VirtualCdrom",
")",
";",
"ok",
"{",
"return",
"c",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"c",
":=",
"l",
".",
"SelectByType",
"(",
"(",
"*",
"types",
".",
"VirtualCdrom",
")",
"(",
"nil",
")",
")",
"\n",
"if",
"len",
"(",
"c",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"c",
"[",
"0",
"]",
".",
"(",
"*",
"types",
".",
"VirtualCdrom",
")",
",",
"nil",
"\n",
"}"
] |
// FindCdrom finds a cdrom device with the given name, defaulting to the first cdrom device if any.
|
[
"FindCdrom",
"finds",
"a",
"cdrom",
"device",
"with",
"the",
"given",
"name",
"defaulting",
"to",
"the",
"first",
"cdrom",
"device",
"if",
"any",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L510-L528
|
21,254
|
vmware/govmomi
|
object/virtual_device_list.go
|
CreateCdrom
|
func (l VirtualDeviceList) CreateCdrom(c *types.VirtualIDEController) (*types.VirtualCdrom, error) {
device := &types.VirtualCdrom{}
l.AssignController(device, c)
l.setDefaultCdromBacking(device)
device.Connectable = &types.VirtualDeviceConnectInfo{
AllowGuestControl: true,
Connected: true,
StartConnected: true,
}
return device, nil
}
|
go
|
func (l VirtualDeviceList) CreateCdrom(c *types.VirtualIDEController) (*types.VirtualCdrom, error) {
device := &types.VirtualCdrom{}
l.AssignController(device, c)
l.setDefaultCdromBacking(device)
device.Connectable = &types.VirtualDeviceConnectInfo{
AllowGuestControl: true,
Connected: true,
StartConnected: true,
}
return device, nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"CreateCdrom",
"(",
"c",
"*",
"types",
".",
"VirtualIDEController",
")",
"(",
"*",
"types",
".",
"VirtualCdrom",
",",
"error",
")",
"{",
"device",
":=",
"&",
"types",
".",
"VirtualCdrom",
"{",
"}",
"\n\n",
"l",
".",
"AssignController",
"(",
"device",
",",
"c",
")",
"\n\n",
"l",
".",
"setDefaultCdromBacking",
"(",
"device",
")",
"\n\n",
"device",
".",
"Connectable",
"=",
"&",
"types",
".",
"VirtualDeviceConnectInfo",
"{",
"AllowGuestControl",
":",
"true",
",",
"Connected",
":",
"true",
",",
"StartConnected",
":",
"true",
",",
"}",
"\n\n",
"return",
"device",
",",
"nil",
"\n",
"}"
] |
// CreateCdrom creates a new VirtualCdrom device which can be added to a VM.
|
[
"CreateCdrom",
"creates",
"a",
"new",
"VirtualCdrom",
"device",
"which",
"can",
"be",
"added",
"to",
"a",
"VM",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L531-L545
|
21,255
|
vmware/govmomi
|
object/virtual_device_list.go
|
InsertIso
|
func (l VirtualDeviceList) InsertIso(device *types.VirtualCdrom, iso string) *types.VirtualCdrom {
device.Backing = &types.VirtualCdromIsoBackingInfo{
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: iso,
},
}
return device
}
|
go
|
func (l VirtualDeviceList) InsertIso(device *types.VirtualCdrom, iso string) *types.VirtualCdrom {
device.Backing = &types.VirtualCdromIsoBackingInfo{
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: iso,
},
}
return device
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"InsertIso",
"(",
"device",
"*",
"types",
".",
"VirtualCdrom",
",",
"iso",
"string",
")",
"*",
"types",
".",
"VirtualCdrom",
"{",
"device",
".",
"Backing",
"=",
"&",
"types",
".",
"VirtualCdromIsoBackingInfo",
"{",
"VirtualDeviceFileBackingInfo",
":",
"types",
".",
"VirtualDeviceFileBackingInfo",
"{",
"FileName",
":",
"iso",
",",
"}",
",",
"}",
"\n\n",
"return",
"device",
"\n",
"}"
] |
// InsertIso changes the cdrom device backing to use the given iso file.
|
[
"InsertIso",
"changes",
"the",
"cdrom",
"device",
"backing",
"to",
"use",
"the",
"given",
"iso",
"file",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L548-L556
|
21,256
|
vmware/govmomi
|
object/virtual_device_list.go
|
EjectIso
|
func (l VirtualDeviceList) EjectIso(device *types.VirtualCdrom) *types.VirtualCdrom {
l.setDefaultCdromBacking(device)
return device
}
|
go
|
func (l VirtualDeviceList) EjectIso(device *types.VirtualCdrom) *types.VirtualCdrom {
l.setDefaultCdromBacking(device)
return device
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"EjectIso",
"(",
"device",
"*",
"types",
".",
"VirtualCdrom",
")",
"*",
"types",
".",
"VirtualCdrom",
"{",
"l",
".",
"setDefaultCdromBacking",
"(",
"device",
")",
"\n",
"return",
"device",
"\n",
"}"
] |
// EjectIso removes the iso file based backing and replaces with the default cdrom backing.
|
[
"EjectIso",
"removes",
"the",
"iso",
"file",
"based",
"backing",
"and",
"replaces",
"with",
"the",
"default",
"cdrom",
"backing",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L559-L562
|
21,257
|
vmware/govmomi
|
object/virtual_device_list.go
|
CreateFloppy
|
func (l VirtualDeviceList) CreateFloppy() (*types.VirtualFloppy, error) {
device := &types.VirtualFloppy{}
c := l.PickController((*types.VirtualSIOController)(nil))
if c == nil {
return nil, errors.New("no available SIO controller")
}
l.AssignController(device, c)
l.setDefaultFloppyBacking(device)
device.Connectable = &types.VirtualDeviceConnectInfo{
AllowGuestControl: true,
Connected: true,
StartConnected: true,
}
return device, nil
}
|
go
|
func (l VirtualDeviceList) CreateFloppy() (*types.VirtualFloppy, error) {
device := &types.VirtualFloppy{}
c := l.PickController((*types.VirtualSIOController)(nil))
if c == nil {
return nil, errors.New("no available SIO controller")
}
l.AssignController(device, c)
l.setDefaultFloppyBacking(device)
device.Connectable = &types.VirtualDeviceConnectInfo{
AllowGuestControl: true,
Connected: true,
StartConnected: true,
}
return device, nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"CreateFloppy",
"(",
")",
"(",
"*",
"types",
".",
"VirtualFloppy",
",",
"error",
")",
"{",
"device",
":=",
"&",
"types",
".",
"VirtualFloppy",
"{",
"}",
"\n\n",
"c",
":=",
"l",
".",
"PickController",
"(",
"(",
"*",
"types",
".",
"VirtualSIOController",
")",
"(",
"nil",
")",
")",
"\n",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"l",
".",
"AssignController",
"(",
"device",
",",
"c",
")",
"\n\n",
"l",
".",
"setDefaultFloppyBacking",
"(",
"device",
")",
"\n\n",
"device",
".",
"Connectable",
"=",
"&",
"types",
".",
"VirtualDeviceConnectInfo",
"{",
"AllowGuestControl",
":",
"true",
",",
"Connected",
":",
"true",
",",
"StartConnected",
":",
"true",
",",
"}",
"\n\n",
"return",
"device",
",",
"nil",
"\n",
"}"
] |
// CreateFloppy creates a new VirtualFloppy device which can be added to a VM.
|
[
"CreateFloppy",
"creates",
"a",
"new",
"VirtualFloppy",
"device",
"which",
"can",
"be",
"added",
"to",
"a",
"VM",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L595-L614
|
21,258
|
vmware/govmomi
|
object/virtual_device_list.go
|
InsertImg
|
func (l VirtualDeviceList) InsertImg(device *types.VirtualFloppy, img string) *types.VirtualFloppy {
device.Backing = &types.VirtualFloppyImageBackingInfo{
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: img,
},
}
return device
}
|
go
|
func (l VirtualDeviceList) InsertImg(device *types.VirtualFloppy, img string) *types.VirtualFloppy {
device.Backing = &types.VirtualFloppyImageBackingInfo{
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: img,
},
}
return device
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"InsertImg",
"(",
"device",
"*",
"types",
".",
"VirtualFloppy",
",",
"img",
"string",
")",
"*",
"types",
".",
"VirtualFloppy",
"{",
"device",
".",
"Backing",
"=",
"&",
"types",
".",
"VirtualFloppyImageBackingInfo",
"{",
"VirtualDeviceFileBackingInfo",
":",
"types",
".",
"VirtualDeviceFileBackingInfo",
"{",
"FileName",
":",
"img",
",",
"}",
",",
"}",
"\n\n",
"return",
"device",
"\n",
"}"
] |
// InsertImg changes the floppy device backing to use the given img file.
|
[
"InsertImg",
"changes",
"the",
"floppy",
"device",
"backing",
"to",
"use",
"the",
"given",
"img",
"file",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L617-L625
|
21,259
|
vmware/govmomi
|
object/virtual_device_list.go
|
EjectImg
|
func (l VirtualDeviceList) EjectImg(device *types.VirtualFloppy) *types.VirtualFloppy {
l.setDefaultFloppyBacking(device)
return device
}
|
go
|
func (l VirtualDeviceList) EjectImg(device *types.VirtualFloppy) *types.VirtualFloppy {
l.setDefaultFloppyBacking(device)
return device
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"EjectImg",
"(",
"device",
"*",
"types",
".",
"VirtualFloppy",
")",
"*",
"types",
".",
"VirtualFloppy",
"{",
"l",
".",
"setDefaultFloppyBacking",
"(",
"device",
")",
"\n",
"return",
"device",
"\n",
"}"
] |
// EjectImg removes the img file based backing and replaces with the default floppy backing.
|
[
"EjectImg",
"removes",
"the",
"img",
"file",
"based",
"backing",
"and",
"replaces",
"with",
"the",
"default",
"floppy",
"backing",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L628-L631
|
21,260
|
vmware/govmomi
|
object/virtual_device_list.go
|
CreateSerialPort
|
func (l VirtualDeviceList) CreateSerialPort() (*types.VirtualSerialPort, error) {
device := &types.VirtualSerialPort{
YieldOnPoll: true,
}
c := l.PickController((*types.VirtualSIOController)(nil))
if c == nil {
return nil, errors.New("no available SIO controller")
}
l.AssignController(device, c)
l.setDefaultSerialPortBacking(device)
return device, nil
}
|
go
|
func (l VirtualDeviceList) CreateSerialPort() (*types.VirtualSerialPort, error) {
device := &types.VirtualSerialPort{
YieldOnPoll: true,
}
c := l.PickController((*types.VirtualSIOController)(nil))
if c == nil {
return nil, errors.New("no available SIO controller")
}
l.AssignController(device, c)
l.setDefaultSerialPortBacking(device)
return device, nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"CreateSerialPort",
"(",
")",
"(",
"*",
"types",
".",
"VirtualSerialPort",
",",
"error",
")",
"{",
"device",
":=",
"&",
"types",
".",
"VirtualSerialPort",
"{",
"YieldOnPoll",
":",
"true",
",",
"}",
"\n\n",
"c",
":=",
"l",
".",
"PickController",
"(",
"(",
"*",
"types",
".",
"VirtualSIOController",
")",
"(",
"nil",
")",
")",
"\n",
"if",
"c",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"l",
".",
"AssignController",
"(",
"device",
",",
"c",
")",
"\n\n",
"l",
".",
"setDefaultSerialPortBacking",
"(",
"device",
")",
"\n\n",
"return",
"device",
",",
"nil",
"\n",
"}"
] |
// CreateSerialPort creates a new VirtualSerialPort device which can be added to a VM.
|
[
"CreateSerialPort",
"creates",
"a",
"new",
"VirtualSerialPort",
"device",
"which",
"can",
"be",
"added",
"to",
"a",
"VM",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L664-L679
|
21,261
|
vmware/govmomi
|
object/virtual_device_list.go
|
ConnectSerialPort
|
func (l VirtualDeviceList) ConnectSerialPort(device *types.VirtualSerialPort, uri string, client bool, proxyuri string) *types.VirtualSerialPort {
if strings.HasPrefix(uri, "[") {
device.Backing = &types.VirtualSerialPortFileBackingInfo{
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: uri,
},
}
return device
}
direction := types.VirtualDeviceURIBackingOptionDirectionServer
if client {
direction = types.VirtualDeviceURIBackingOptionDirectionClient
}
device.Backing = &types.VirtualSerialPortURIBackingInfo{
VirtualDeviceURIBackingInfo: types.VirtualDeviceURIBackingInfo{
Direction: string(direction),
ServiceURI: uri,
ProxyURI: proxyuri,
},
}
return device
}
|
go
|
func (l VirtualDeviceList) ConnectSerialPort(device *types.VirtualSerialPort, uri string, client bool, proxyuri string) *types.VirtualSerialPort {
if strings.HasPrefix(uri, "[") {
device.Backing = &types.VirtualSerialPortFileBackingInfo{
VirtualDeviceFileBackingInfo: types.VirtualDeviceFileBackingInfo{
FileName: uri,
},
}
return device
}
direction := types.VirtualDeviceURIBackingOptionDirectionServer
if client {
direction = types.VirtualDeviceURIBackingOptionDirectionClient
}
device.Backing = &types.VirtualSerialPortURIBackingInfo{
VirtualDeviceURIBackingInfo: types.VirtualDeviceURIBackingInfo{
Direction: string(direction),
ServiceURI: uri,
ProxyURI: proxyuri,
},
}
return device
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"ConnectSerialPort",
"(",
"device",
"*",
"types",
".",
"VirtualSerialPort",
",",
"uri",
"string",
",",
"client",
"bool",
",",
"proxyuri",
"string",
")",
"*",
"types",
".",
"VirtualSerialPort",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"uri",
",",
"\"",
"\"",
")",
"{",
"device",
".",
"Backing",
"=",
"&",
"types",
".",
"VirtualSerialPortFileBackingInfo",
"{",
"VirtualDeviceFileBackingInfo",
":",
"types",
".",
"VirtualDeviceFileBackingInfo",
"{",
"FileName",
":",
"uri",
",",
"}",
",",
"}",
"\n\n",
"return",
"device",
"\n",
"}",
"\n\n",
"direction",
":=",
"types",
".",
"VirtualDeviceURIBackingOptionDirectionServer",
"\n",
"if",
"client",
"{",
"direction",
"=",
"types",
".",
"VirtualDeviceURIBackingOptionDirectionClient",
"\n",
"}",
"\n\n",
"device",
".",
"Backing",
"=",
"&",
"types",
".",
"VirtualSerialPortURIBackingInfo",
"{",
"VirtualDeviceURIBackingInfo",
":",
"types",
".",
"VirtualDeviceURIBackingInfo",
"{",
"Direction",
":",
"string",
"(",
"direction",
")",
",",
"ServiceURI",
":",
"uri",
",",
"ProxyURI",
":",
"proxyuri",
",",
"}",
",",
"}",
"\n\n",
"return",
"device",
"\n",
"}"
] |
// ConnectSerialPort connects a serial port to a server or client uri.
|
[
"ConnectSerialPort",
"connects",
"a",
"serial",
"port",
"to",
"a",
"server",
"or",
"client",
"uri",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L682-L707
|
21,262
|
vmware/govmomi
|
object/virtual_device_list.go
|
DisconnectSerialPort
|
func (l VirtualDeviceList) DisconnectSerialPort(device *types.VirtualSerialPort) *types.VirtualSerialPort {
l.setDefaultSerialPortBacking(device)
return device
}
|
go
|
func (l VirtualDeviceList) DisconnectSerialPort(device *types.VirtualSerialPort) *types.VirtualSerialPort {
l.setDefaultSerialPortBacking(device)
return device
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"DisconnectSerialPort",
"(",
"device",
"*",
"types",
".",
"VirtualSerialPort",
")",
"*",
"types",
".",
"VirtualSerialPort",
"{",
"l",
".",
"setDefaultSerialPortBacking",
"(",
"device",
")",
"\n",
"return",
"device",
"\n",
"}"
] |
// DisconnectSerialPort disconnects the serial port backing.
|
[
"DisconnectSerialPort",
"disconnects",
"the",
"serial",
"port",
"backing",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L710-L713
|
21,263
|
vmware/govmomi
|
object/virtual_device_list.go
|
CreateEthernetCard
|
func (l VirtualDeviceList) CreateEthernetCard(name string, backing types.BaseVirtualDeviceBackingInfo) (types.BaseVirtualDevice, error) {
ctypes := EthernetCardTypes()
if name == "" {
name = ctypes.deviceName(ctypes[0])
}
found := ctypes.Select(func(device types.BaseVirtualDevice) bool {
return l.deviceName(device) == name
})
if len(found) == 0 {
return nil, fmt.Errorf("unknown ethernet card type '%s'", name)
}
c, ok := found[0].(types.BaseVirtualEthernetCard)
if !ok {
return nil, fmt.Errorf("invalid ethernet card type '%s'", name)
}
c.GetVirtualEthernetCard().Backing = backing
return c.(types.BaseVirtualDevice), nil
}
|
go
|
func (l VirtualDeviceList) CreateEthernetCard(name string, backing types.BaseVirtualDeviceBackingInfo) (types.BaseVirtualDevice, error) {
ctypes := EthernetCardTypes()
if name == "" {
name = ctypes.deviceName(ctypes[0])
}
found := ctypes.Select(func(device types.BaseVirtualDevice) bool {
return l.deviceName(device) == name
})
if len(found) == 0 {
return nil, fmt.Errorf("unknown ethernet card type '%s'", name)
}
c, ok := found[0].(types.BaseVirtualEthernetCard)
if !ok {
return nil, fmt.Errorf("invalid ethernet card type '%s'", name)
}
c.GetVirtualEthernetCard().Backing = backing
return c.(types.BaseVirtualDevice), nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"CreateEthernetCard",
"(",
"name",
"string",
",",
"backing",
"types",
".",
"BaseVirtualDeviceBackingInfo",
")",
"(",
"types",
".",
"BaseVirtualDevice",
",",
"error",
")",
"{",
"ctypes",
":=",
"EthernetCardTypes",
"(",
")",
"\n\n",
"if",
"name",
"==",
"\"",
"\"",
"{",
"name",
"=",
"ctypes",
".",
"deviceName",
"(",
"ctypes",
"[",
"0",
"]",
")",
"\n",
"}",
"\n\n",
"found",
":=",
"ctypes",
".",
"Select",
"(",
"func",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"bool",
"{",
"return",
"l",
".",
"deviceName",
"(",
"device",
")",
"==",
"name",
"\n",
"}",
")",
"\n\n",
"if",
"len",
"(",
"found",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"c",
",",
"ok",
":=",
"found",
"[",
"0",
"]",
".",
"(",
"types",
".",
"BaseVirtualEthernetCard",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n\n",
"c",
".",
"GetVirtualEthernetCard",
"(",
")",
".",
"Backing",
"=",
"backing",
"\n\n",
"return",
"c",
".",
"(",
"types",
".",
"BaseVirtualDevice",
")",
",",
"nil",
"\n",
"}"
] |
// CreateEthernetCard creates a new VirtualEthernetCard of the given name name and initialized with the given backing.
|
[
"CreateEthernetCard",
"creates",
"a",
"new",
"VirtualEthernetCard",
"of",
"the",
"given",
"name",
"name",
"and",
"initialized",
"with",
"the",
"given",
"backing",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L725-L748
|
21,264
|
vmware/govmomi
|
object/virtual_device_list.go
|
PrimaryMacAddress
|
func (l VirtualDeviceList) PrimaryMacAddress() string {
eth0 := l.Find("ethernet-0")
if eth0 == nil {
return ""
}
return eth0.(types.BaseVirtualEthernetCard).GetVirtualEthernetCard().MacAddress
}
|
go
|
func (l VirtualDeviceList) PrimaryMacAddress() string {
eth0 := l.Find("ethernet-0")
if eth0 == nil {
return ""
}
return eth0.(types.BaseVirtualEthernetCard).GetVirtualEthernetCard().MacAddress
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"PrimaryMacAddress",
"(",
")",
"string",
"{",
"eth0",
":=",
"l",
".",
"Find",
"(",
"\"",
"\"",
")",
"\n\n",
"if",
"eth0",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n\n",
"return",
"eth0",
".",
"(",
"types",
".",
"BaseVirtualEthernetCard",
")",
".",
"GetVirtualEthernetCard",
"(",
")",
".",
"MacAddress",
"\n",
"}"
] |
// PrimaryMacAddress returns the MacAddress field of the primary VirtualEthernetCard
|
[
"PrimaryMacAddress",
"returns",
"the",
"MacAddress",
"field",
"of",
"the",
"primary",
"VirtualEthernetCard"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L751-L759
|
21,265
|
vmware/govmomi
|
object/virtual_device_list.go
|
SelectBootOrder
|
func (l VirtualDeviceList) SelectBootOrder(order []types.BaseVirtualMachineBootOptionsBootableDevice) VirtualDeviceList {
var devices VirtualDeviceList
for _, bd := range order {
for _, device := range l {
if kind, ok := bootableDevices[l.Type(device)]; ok {
if reflect.DeepEqual(kind(device), bd) {
devices = append(devices, device)
}
}
}
}
return devices
}
|
go
|
func (l VirtualDeviceList) SelectBootOrder(order []types.BaseVirtualMachineBootOptionsBootableDevice) VirtualDeviceList {
var devices VirtualDeviceList
for _, bd := range order {
for _, device := range l {
if kind, ok := bootableDevices[l.Type(device)]; ok {
if reflect.DeepEqual(kind(device), bd) {
devices = append(devices, device)
}
}
}
}
return devices
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"SelectBootOrder",
"(",
"order",
"[",
"]",
"types",
".",
"BaseVirtualMachineBootOptionsBootableDevice",
")",
"VirtualDeviceList",
"{",
"var",
"devices",
"VirtualDeviceList",
"\n\n",
"for",
"_",
",",
"bd",
":=",
"range",
"order",
"{",
"for",
"_",
",",
"device",
":=",
"range",
"l",
"{",
"if",
"kind",
",",
"ok",
":=",
"bootableDevices",
"[",
"l",
".",
"Type",
"(",
"device",
")",
"]",
";",
"ok",
"{",
"if",
"reflect",
".",
"DeepEqual",
"(",
"kind",
"(",
"device",
")",
",",
"bd",
")",
"{",
"devices",
"=",
"append",
"(",
"devices",
",",
"device",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"devices",
"\n",
"}"
] |
// SelectBootOrder returns an ordered list of devices matching the given bootable device order
|
[
"SelectBootOrder",
"returns",
"an",
"ordered",
"list",
"of",
"devices",
"matching",
"the",
"given",
"bootable",
"device",
"order"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L817-L831
|
21,266
|
vmware/govmomi
|
object/virtual_device_list.go
|
TypeName
|
func (l VirtualDeviceList) TypeName(device types.BaseVirtualDevice) string {
dtype := reflect.TypeOf(device)
if dtype == nil {
return ""
}
return dtype.Elem().Name()
}
|
go
|
func (l VirtualDeviceList) TypeName(device types.BaseVirtualDevice) string {
dtype := reflect.TypeOf(device)
if dtype == nil {
return ""
}
return dtype.Elem().Name()
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"TypeName",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"string",
"{",
"dtype",
":=",
"reflect",
".",
"TypeOf",
"(",
"device",
")",
"\n",
"if",
"dtype",
"==",
"nil",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"dtype",
".",
"Elem",
"(",
")",
".",
"Name",
"(",
")",
"\n",
"}"
] |
// TypeName returns the vmodl type name of the device
|
[
"TypeName",
"returns",
"the",
"vmodl",
"type",
"name",
"of",
"the",
"device"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L834-L840
|
21,267
|
vmware/govmomi
|
object/virtual_device_list.go
|
Type
|
func (l VirtualDeviceList) Type(device types.BaseVirtualDevice) string {
switch device.(type) {
case types.BaseVirtualEthernetCard:
return DeviceTypeEthernet
case *types.ParaVirtualSCSIController:
return "pvscsi"
case *types.VirtualLsiLogicSASController:
return "lsilogic-sas"
case *types.VirtualNVMEController:
return "nvme"
default:
return l.deviceName(device)
}
}
|
go
|
func (l VirtualDeviceList) Type(device types.BaseVirtualDevice) string {
switch device.(type) {
case types.BaseVirtualEthernetCard:
return DeviceTypeEthernet
case *types.ParaVirtualSCSIController:
return "pvscsi"
case *types.VirtualLsiLogicSASController:
return "lsilogic-sas"
case *types.VirtualNVMEController:
return "nvme"
default:
return l.deviceName(device)
}
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"Type",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"string",
"{",
"switch",
"device",
".",
"(",
"type",
")",
"{",
"case",
"types",
".",
"BaseVirtualEthernetCard",
":",
"return",
"DeviceTypeEthernet",
"\n",
"case",
"*",
"types",
".",
"ParaVirtualSCSIController",
":",
"return",
"\"",
"\"",
"\n",
"case",
"*",
"types",
".",
"VirtualLsiLogicSASController",
":",
"return",
"\"",
"\"",
"\n",
"case",
"*",
"types",
".",
"VirtualNVMEController",
":",
"return",
"\"",
"\"",
"\n",
"default",
":",
"return",
"l",
".",
"deviceName",
"(",
"device",
")",
"\n",
"}",
"\n",
"}"
] |
// Type returns a human-readable name for the given device
|
[
"Type",
"returns",
"a",
"human",
"-",
"readable",
"name",
"for",
"the",
"given",
"device"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L857-L870
|
21,268
|
vmware/govmomi
|
object/virtual_device_list.go
|
Name
|
func (l VirtualDeviceList) Name(device types.BaseVirtualDevice) string {
var key string
var UnitNumber int32
d := device.GetVirtualDevice()
if d.UnitNumber != nil {
UnitNumber = *d.UnitNumber
}
dtype := l.Type(device)
switch dtype {
case DeviceTypeEthernet:
key = fmt.Sprintf("%d", UnitNumber-7)
case DeviceTypeDisk:
key = fmt.Sprintf("%d-%d", d.ControllerKey, UnitNumber)
default:
key = fmt.Sprintf("%d", d.Key)
}
return fmt.Sprintf("%s-%s", dtype, key)
}
|
go
|
func (l VirtualDeviceList) Name(device types.BaseVirtualDevice) string {
var key string
var UnitNumber int32
d := device.GetVirtualDevice()
if d.UnitNumber != nil {
UnitNumber = *d.UnitNumber
}
dtype := l.Type(device)
switch dtype {
case DeviceTypeEthernet:
key = fmt.Sprintf("%d", UnitNumber-7)
case DeviceTypeDisk:
key = fmt.Sprintf("%d-%d", d.ControllerKey, UnitNumber)
default:
key = fmt.Sprintf("%d", d.Key)
}
return fmt.Sprintf("%s-%s", dtype, key)
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"Name",
"(",
"device",
"types",
".",
"BaseVirtualDevice",
")",
"string",
"{",
"var",
"key",
"string",
"\n",
"var",
"UnitNumber",
"int32",
"\n",
"d",
":=",
"device",
".",
"GetVirtualDevice",
"(",
")",
"\n",
"if",
"d",
".",
"UnitNumber",
"!=",
"nil",
"{",
"UnitNumber",
"=",
"*",
"d",
".",
"UnitNumber",
"\n",
"}",
"\n\n",
"dtype",
":=",
"l",
".",
"Type",
"(",
"device",
")",
"\n",
"switch",
"dtype",
"{",
"case",
"DeviceTypeEthernet",
":",
"key",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"UnitNumber",
"-",
"7",
")",
"\n",
"case",
"DeviceTypeDisk",
":",
"key",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"d",
".",
"ControllerKey",
",",
"UnitNumber",
")",
"\n",
"default",
":",
"key",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"d",
".",
"Key",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"dtype",
",",
"key",
")",
"\n",
"}"
] |
// Name returns a stable, human-readable name for the given device
|
[
"Name",
"returns",
"a",
"stable",
"human",
"-",
"readable",
"name",
"for",
"the",
"given",
"device"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L873-L892
|
21,269
|
vmware/govmomi
|
object/virtual_device_list.go
|
ConfigSpec
|
func (l VirtualDeviceList) ConfigSpec(op types.VirtualDeviceConfigSpecOperation) ([]types.BaseVirtualDeviceConfigSpec, error) {
var fop types.VirtualDeviceConfigSpecFileOperation
switch op {
case types.VirtualDeviceConfigSpecOperationAdd:
fop = types.VirtualDeviceConfigSpecFileOperationCreate
case types.VirtualDeviceConfigSpecOperationEdit:
fop = types.VirtualDeviceConfigSpecFileOperationReplace
case types.VirtualDeviceConfigSpecOperationRemove:
fop = types.VirtualDeviceConfigSpecFileOperationDestroy
default:
panic("unknown op")
}
var res []types.BaseVirtualDeviceConfigSpec
for _, device := range l {
config := &types.VirtualDeviceConfigSpec{
Device: device,
Operation: op,
}
if disk, ok := device.(*types.VirtualDisk); ok {
config.FileOperation = fop
// Special case to attach an existing disk
if op == types.VirtualDeviceConfigSpecOperationAdd && disk.CapacityInKB == 0 {
childDisk := false
if b, ok := disk.Backing.(*types.VirtualDiskFlatVer2BackingInfo); ok {
childDisk = b.Parent != nil
}
if !childDisk {
// Existing disk, clear file operation
config.FileOperation = ""
}
}
}
res = append(res, config)
}
return res, nil
}
|
go
|
func (l VirtualDeviceList) ConfigSpec(op types.VirtualDeviceConfigSpecOperation) ([]types.BaseVirtualDeviceConfigSpec, error) {
var fop types.VirtualDeviceConfigSpecFileOperation
switch op {
case types.VirtualDeviceConfigSpecOperationAdd:
fop = types.VirtualDeviceConfigSpecFileOperationCreate
case types.VirtualDeviceConfigSpecOperationEdit:
fop = types.VirtualDeviceConfigSpecFileOperationReplace
case types.VirtualDeviceConfigSpecOperationRemove:
fop = types.VirtualDeviceConfigSpecFileOperationDestroy
default:
panic("unknown op")
}
var res []types.BaseVirtualDeviceConfigSpec
for _, device := range l {
config := &types.VirtualDeviceConfigSpec{
Device: device,
Operation: op,
}
if disk, ok := device.(*types.VirtualDisk); ok {
config.FileOperation = fop
// Special case to attach an existing disk
if op == types.VirtualDeviceConfigSpecOperationAdd && disk.CapacityInKB == 0 {
childDisk := false
if b, ok := disk.Backing.(*types.VirtualDiskFlatVer2BackingInfo); ok {
childDisk = b.Parent != nil
}
if !childDisk {
// Existing disk, clear file operation
config.FileOperation = ""
}
}
}
res = append(res, config)
}
return res, nil
}
|
[
"func",
"(",
"l",
"VirtualDeviceList",
")",
"ConfigSpec",
"(",
"op",
"types",
".",
"VirtualDeviceConfigSpecOperation",
")",
"(",
"[",
"]",
"types",
".",
"BaseVirtualDeviceConfigSpec",
",",
"error",
")",
"{",
"var",
"fop",
"types",
".",
"VirtualDeviceConfigSpecFileOperation",
"\n",
"switch",
"op",
"{",
"case",
"types",
".",
"VirtualDeviceConfigSpecOperationAdd",
":",
"fop",
"=",
"types",
".",
"VirtualDeviceConfigSpecFileOperationCreate",
"\n",
"case",
"types",
".",
"VirtualDeviceConfigSpecOperationEdit",
":",
"fop",
"=",
"types",
".",
"VirtualDeviceConfigSpecFileOperationReplace",
"\n",
"case",
"types",
".",
"VirtualDeviceConfigSpecOperationRemove",
":",
"fop",
"=",
"types",
".",
"VirtualDeviceConfigSpecFileOperationDestroy",
"\n",
"default",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"res",
"[",
"]",
"types",
".",
"BaseVirtualDeviceConfigSpec",
"\n",
"for",
"_",
",",
"device",
":=",
"range",
"l",
"{",
"config",
":=",
"&",
"types",
".",
"VirtualDeviceConfigSpec",
"{",
"Device",
":",
"device",
",",
"Operation",
":",
"op",
",",
"}",
"\n\n",
"if",
"disk",
",",
"ok",
":=",
"device",
".",
"(",
"*",
"types",
".",
"VirtualDisk",
")",
";",
"ok",
"{",
"config",
".",
"FileOperation",
"=",
"fop",
"\n\n",
"// Special case to attach an existing disk",
"if",
"op",
"==",
"types",
".",
"VirtualDeviceConfigSpecOperationAdd",
"&&",
"disk",
".",
"CapacityInKB",
"==",
"0",
"{",
"childDisk",
":=",
"false",
"\n",
"if",
"b",
",",
"ok",
":=",
"disk",
".",
"Backing",
".",
"(",
"*",
"types",
".",
"VirtualDiskFlatVer2BackingInfo",
")",
";",
"ok",
"{",
"childDisk",
"=",
"b",
".",
"Parent",
"!=",
"nil",
"\n",
"}",
"\n\n",
"if",
"!",
"childDisk",
"{",
"// Existing disk, clear file operation",
"config",
".",
"FileOperation",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"res",
"=",
"append",
"(",
"res",
",",
"config",
")",
"\n",
"}",
"\n\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] |
// ConfigSpec creates a virtual machine configuration spec for
// the specified operation, for the list of devices in the device list.
|
[
"ConfigSpec",
"creates",
"a",
"virtual",
"machine",
"configuration",
"spec",
"for",
"the",
"specified",
"operation",
"for",
"the",
"list",
"of",
"devices",
"in",
"the",
"device",
"list",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_device_list.go#L896-L937
|
21,270
|
vmware/govmomi
|
object/host_certificate_manager.go
|
NewHostCertificateManager
|
func NewHostCertificateManager(c *vim25.Client, ref types.ManagedObjectReference, host types.ManagedObjectReference) *HostCertificateManager {
return &HostCertificateManager{
Common: NewCommon(c, ref),
Host: NewHostSystem(c, host),
}
}
|
go
|
func NewHostCertificateManager(c *vim25.Client, ref types.ManagedObjectReference, host types.ManagedObjectReference) *HostCertificateManager {
return &HostCertificateManager{
Common: NewCommon(c, ref),
Host: NewHostSystem(c, host),
}
}
|
[
"func",
"NewHostCertificateManager",
"(",
"c",
"*",
"vim25",
".",
"Client",
",",
"ref",
"types",
".",
"ManagedObjectReference",
",",
"host",
"types",
".",
"ManagedObjectReference",
")",
"*",
"HostCertificateManager",
"{",
"return",
"&",
"HostCertificateManager",
"{",
"Common",
":",
"NewCommon",
"(",
"c",
",",
"ref",
")",
",",
"Host",
":",
"NewHostSystem",
"(",
"c",
",",
"host",
")",
",",
"}",
"\n",
"}"
] |
// NewHostCertificateManager creates a new HostCertificateManager helper
|
[
"NewHostCertificateManager",
"creates",
"a",
"new",
"HostCertificateManager",
"helper"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_certificate_manager.go#L36-L41
|
21,271
|
vmware/govmomi
|
object/host_certificate_manager.go
|
CertificateInfo
|
func (m HostCertificateManager) CertificateInfo(ctx context.Context) (*HostCertificateInfo, error) {
var hs mo.HostSystem
var cm mo.HostCertificateManager
pc := property.DefaultCollector(m.Client())
err := pc.RetrieveOne(ctx, m.Reference(), []string{"certificateInfo"}, &cm)
if err != nil {
return nil, err
}
_ = pc.RetrieveOne(ctx, m.Host.Reference(), []string{"summary.config.sslThumbprint"}, &hs)
return &HostCertificateInfo{
HostCertificateManagerCertificateInfo: cm.CertificateInfo,
ThumbprintSHA1: hs.Summary.Config.SslThumbprint,
}, nil
}
|
go
|
func (m HostCertificateManager) CertificateInfo(ctx context.Context) (*HostCertificateInfo, error) {
var hs mo.HostSystem
var cm mo.HostCertificateManager
pc := property.DefaultCollector(m.Client())
err := pc.RetrieveOne(ctx, m.Reference(), []string{"certificateInfo"}, &cm)
if err != nil {
return nil, err
}
_ = pc.RetrieveOne(ctx, m.Host.Reference(), []string{"summary.config.sslThumbprint"}, &hs)
return &HostCertificateInfo{
HostCertificateManagerCertificateInfo: cm.CertificateInfo,
ThumbprintSHA1: hs.Summary.Config.SslThumbprint,
}, nil
}
|
[
"func",
"(",
"m",
"HostCertificateManager",
")",
"CertificateInfo",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"HostCertificateInfo",
",",
"error",
")",
"{",
"var",
"hs",
"mo",
".",
"HostSystem",
"\n",
"var",
"cm",
"mo",
".",
"HostCertificateManager",
"\n\n",
"pc",
":=",
"property",
".",
"DefaultCollector",
"(",
"m",
".",
"Client",
"(",
")",
")",
"\n\n",
"err",
":=",
"pc",
".",
"RetrieveOne",
"(",
"ctx",
",",
"m",
".",
"Reference",
"(",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"&",
"cm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"_",
"=",
"pc",
".",
"RetrieveOne",
"(",
"ctx",
",",
"m",
".",
"Host",
".",
"Reference",
"(",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"&",
"hs",
")",
"\n\n",
"return",
"&",
"HostCertificateInfo",
"{",
"HostCertificateManagerCertificateInfo",
":",
"cm",
".",
"CertificateInfo",
",",
"ThumbprintSHA1",
":",
"hs",
".",
"Summary",
".",
"Config",
".",
"SslThumbprint",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// CertificateInfo wraps the host CertificateManager certificateInfo property with the HostCertificateInfo helper.
// The ThumbprintSHA1 field is set to HostSystem.Summary.Config.SslThumbprint if the host system is managed by a vCenter.
|
[
"CertificateInfo",
"wraps",
"the",
"host",
"CertificateManager",
"certificateInfo",
"property",
"with",
"the",
"HostCertificateInfo",
"helper",
".",
"The",
"ThumbprintSHA1",
"field",
"is",
"set",
"to",
"HostSystem",
".",
"Summary",
".",
"Config",
".",
"SslThumbprint",
"if",
"the",
"host",
"system",
"is",
"managed",
"by",
"a",
"vCenter",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_certificate_manager.go#L45-L62
|
21,272
|
vmware/govmomi
|
object/host_certificate_manager.go
|
InstallServerCertificate
|
func (m HostCertificateManager) InstallServerCertificate(ctx context.Context, cert string) error {
req := types.InstallServerCertificate{
This: m.Reference(),
Cert: cert,
}
_, err := methods.InstallServerCertificate(ctx, m.Client(), &req)
if err != nil {
return err
}
// NotifyAffectedService is internal, not exposing as we don't have a use case other than with InstallServerCertificate
// Without this call, hostd needs to be restarted to use the updated certificate
// Note: using Refresh as it has the same struct/signature, we just need to use different xml name tags
body := struct {
Req *types.Refresh `xml:"urn:vim25 NotifyAffectedServices,omitempty"`
Res *types.RefreshResponse `xml:"urn:vim25 NotifyAffectedServicesResponse,omitempty"`
methods.RefreshBody
}{
Req: &types.Refresh{This: m.Reference()},
}
return m.Client().RoundTrip(ctx, &body, &body)
}
|
go
|
func (m HostCertificateManager) InstallServerCertificate(ctx context.Context, cert string) error {
req := types.InstallServerCertificate{
This: m.Reference(),
Cert: cert,
}
_, err := methods.InstallServerCertificate(ctx, m.Client(), &req)
if err != nil {
return err
}
// NotifyAffectedService is internal, not exposing as we don't have a use case other than with InstallServerCertificate
// Without this call, hostd needs to be restarted to use the updated certificate
// Note: using Refresh as it has the same struct/signature, we just need to use different xml name tags
body := struct {
Req *types.Refresh `xml:"urn:vim25 NotifyAffectedServices,omitempty"`
Res *types.RefreshResponse `xml:"urn:vim25 NotifyAffectedServicesResponse,omitempty"`
methods.RefreshBody
}{
Req: &types.Refresh{This: m.Reference()},
}
return m.Client().RoundTrip(ctx, &body, &body)
}
|
[
"func",
"(",
"m",
"HostCertificateManager",
")",
"InstallServerCertificate",
"(",
"ctx",
"context",
".",
"Context",
",",
"cert",
"string",
")",
"error",
"{",
"req",
":=",
"types",
".",
"InstallServerCertificate",
"{",
"This",
":",
"m",
".",
"Reference",
"(",
")",
",",
"Cert",
":",
"cert",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"InstallServerCertificate",
"(",
"ctx",
",",
"m",
".",
"Client",
"(",
")",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// NotifyAffectedService is internal, not exposing as we don't have a use case other than with InstallServerCertificate",
"// Without this call, hostd needs to be restarted to use the updated certificate",
"// Note: using Refresh as it has the same struct/signature, we just need to use different xml name tags",
"body",
":=",
"struct",
"{",
"Req",
"*",
"types",
".",
"Refresh",
"`xml:\"urn:vim25 NotifyAffectedServices,omitempty\"`",
"\n",
"Res",
"*",
"types",
".",
"RefreshResponse",
"`xml:\"urn:vim25 NotifyAffectedServicesResponse,omitempty\"`",
"\n",
"methods",
".",
"RefreshBody",
"\n",
"}",
"{",
"Req",
":",
"&",
"types",
".",
"Refresh",
"{",
"This",
":",
"m",
".",
"Reference",
"(",
")",
"}",
",",
"}",
"\n\n",
"return",
"m",
".",
"Client",
"(",
")",
".",
"RoundTrip",
"(",
"ctx",
",",
"&",
"body",
",",
"&",
"body",
")",
"\n",
"}"
] |
// InstallServerCertificate imports the given SSL certificate to the host system.
|
[
"InstallServerCertificate",
"imports",
"the",
"given",
"SSL",
"certificate",
"to",
"the",
"host",
"system",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_certificate_manager.go#L98-L121
|
21,273
|
vmware/govmomi
|
object/host_certificate_manager.go
|
ListCACertificateRevocationLists
|
func (m HostCertificateManager) ListCACertificateRevocationLists(ctx context.Context) ([]string, error) {
req := types.ListCACertificateRevocationLists{
This: m.Reference(),
}
res, err := methods.ListCACertificateRevocationLists(ctx, m.Client(), &req)
if err != nil {
return nil, err
}
return res.Returnval, nil
}
|
go
|
func (m HostCertificateManager) ListCACertificateRevocationLists(ctx context.Context) ([]string, error) {
req := types.ListCACertificateRevocationLists{
This: m.Reference(),
}
res, err := methods.ListCACertificateRevocationLists(ctx, m.Client(), &req)
if err != nil {
return nil, err
}
return res.Returnval, nil
}
|
[
"func",
"(",
"m",
"HostCertificateManager",
")",
"ListCACertificateRevocationLists",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"ListCACertificateRevocationLists",
"{",
"This",
":",
"m",
".",
"Reference",
"(",
")",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"ListCACertificateRevocationLists",
"(",
"ctx",
",",
"m",
".",
"Client",
"(",
")",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"res",
".",
"Returnval",
",",
"nil",
"\n",
"}"
] |
// ListCACertificateRevocationLists returns the SSL CRLs of Certificate Authorities that are trusted by the host system.
|
[
"ListCACertificateRevocationLists",
"returns",
"the",
"SSL",
"CRLs",
"of",
"Certificate",
"Authorities",
"that",
"are",
"trusted",
"by",
"the",
"host",
"system",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_certificate_manager.go#L124-L135
|
21,274
|
vmware/govmomi
|
object/host_certificate_manager.go
|
ReplaceCACertificatesAndCRLs
|
func (m HostCertificateManager) ReplaceCACertificatesAndCRLs(ctx context.Context, caCert []string, caCrl []string) error {
req := types.ReplaceCACertificatesAndCRLs{
This: m.Reference(),
CaCert: caCert,
CaCrl: caCrl,
}
_, err := methods.ReplaceCACertificatesAndCRLs(ctx, m.Client(), &req)
return err
}
|
go
|
func (m HostCertificateManager) ReplaceCACertificatesAndCRLs(ctx context.Context, caCert []string, caCrl []string) error {
req := types.ReplaceCACertificatesAndCRLs{
This: m.Reference(),
CaCert: caCert,
CaCrl: caCrl,
}
_, err := methods.ReplaceCACertificatesAndCRLs(ctx, m.Client(), &req)
return err
}
|
[
"func",
"(",
"m",
"HostCertificateManager",
")",
"ReplaceCACertificatesAndCRLs",
"(",
"ctx",
"context",
".",
"Context",
",",
"caCert",
"[",
"]",
"string",
",",
"caCrl",
"[",
"]",
"string",
")",
"error",
"{",
"req",
":=",
"types",
".",
"ReplaceCACertificatesAndCRLs",
"{",
"This",
":",
"m",
".",
"Reference",
"(",
")",
",",
"CaCert",
":",
"caCert",
",",
"CaCrl",
":",
"caCrl",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"ReplaceCACertificatesAndCRLs",
"(",
"ctx",
",",
"m",
".",
"Client",
"(",
")",
",",
"&",
"req",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// ReplaceCACertificatesAndCRLs replaces the trusted CA certificates and CRL used by the host system.
// These determine whether the server can verify the identity of an external entity.
|
[
"ReplaceCACertificatesAndCRLs",
"replaces",
"the",
"trusted",
"CA",
"certificates",
"and",
"CRL",
"used",
"by",
"the",
"host",
"system",
".",
"These",
"determine",
"whether",
"the",
"server",
"can",
"verify",
"the",
"identity",
"of",
"an",
"external",
"entity",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/host_certificate_manager.go#L153-L162
|
21,275
|
vmware/govmomi
|
simulator/session_manager.go
|
mapSession
|
func (c *Context) mapSession() {
if cookie, err := c.req.Cookie(soap.SessionCookieName); err == nil {
if val, ok := c.svc.sm.sessions[cookie.Value]; ok {
c.SetSession(val, false)
}
}
}
|
go
|
func (c *Context) mapSession() {
if cookie, err := c.req.Cookie(soap.SessionCookieName); err == nil {
if val, ok := c.svc.sm.sessions[cookie.Value]; ok {
c.SetSession(val, false)
}
}
}
|
[
"func",
"(",
"c",
"*",
"Context",
")",
"mapSession",
"(",
")",
"{",
"if",
"cookie",
",",
"err",
":=",
"c",
".",
"req",
".",
"Cookie",
"(",
"soap",
".",
"SessionCookieName",
")",
";",
"err",
"==",
"nil",
"{",
"if",
"val",
",",
"ok",
":=",
"c",
".",
"svc",
".",
"sm",
".",
"sessions",
"[",
"cookie",
".",
"Value",
"]",
";",
"ok",
"{",
"c",
".",
"SetSession",
"(",
"val",
",",
"false",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] |
// mapSession maps an HTTP cookie to a Session.
|
[
"mapSession",
"maps",
"an",
"HTTP",
"cookie",
"to",
"a",
"Session",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/session_manager.go#L265-L271
|
21,276
|
vmware/govmomi
|
simulator/session_manager.go
|
SetSession
|
func (c *Context) SetSession(session Session, login bool) {
session.UserAgent = c.req.UserAgent()
session.IpAddress = strings.Split(c.req.RemoteAddr, ":")[0]
session.LastActiveTime = time.Now()
session.CallCount++
c.svc.sm.sessions[session.Key] = session
c.Session = &session
if login {
http.SetCookie(c.res, &http.Cookie{
Name: soap.SessionCookieName,
Value: session.Key,
})
c.postEvent(&types.UserLoginSessionEvent{
SessionId: session.Key,
IpAddress: session.IpAddress,
UserAgent: session.UserAgent,
Locale: session.Locale,
})
}
}
|
go
|
func (c *Context) SetSession(session Session, login bool) {
session.UserAgent = c.req.UserAgent()
session.IpAddress = strings.Split(c.req.RemoteAddr, ":")[0]
session.LastActiveTime = time.Now()
session.CallCount++
c.svc.sm.sessions[session.Key] = session
c.Session = &session
if login {
http.SetCookie(c.res, &http.Cookie{
Name: soap.SessionCookieName,
Value: session.Key,
})
c.postEvent(&types.UserLoginSessionEvent{
SessionId: session.Key,
IpAddress: session.IpAddress,
UserAgent: session.UserAgent,
Locale: session.Locale,
})
}
}
|
[
"func",
"(",
"c",
"*",
"Context",
")",
"SetSession",
"(",
"session",
"Session",
",",
"login",
"bool",
")",
"{",
"session",
".",
"UserAgent",
"=",
"c",
".",
"req",
".",
"UserAgent",
"(",
")",
"\n",
"session",
".",
"IpAddress",
"=",
"strings",
".",
"Split",
"(",
"c",
".",
"req",
".",
"RemoteAddr",
",",
"\"",
"\"",
")",
"[",
"0",
"]",
"\n",
"session",
".",
"LastActiveTime",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"session",
".",
"CallCount",
"++",
"\n\n",
"c",
".",
"svc",
".",
"sm",
".",
"sessions",
"[",
"session",
".",
"Key",
"]",
"=",
"session",
"\n",
"c",
".",
"Session",
"=",
"&",
"session",
"\n\n",
"if",
"login",
"{",
"http",
".",
"SetCookie",
"(",
"c",
".",
"res",
",",
"&",
"http",
".",
"Cookie",
"{",
"Name",
":",
"soap",
".",
"SessionCookieName",
",",
"Value",
":",
"session",
".",
"Key",
",",
"}",
")",
"\n\n",
"c",
".",
"postEvent",
"(",
"&",
"types",
".",
"UserLoginSessionEvent",
"{",
"SessionId",
":",
"session",
".",
"Key",
",",
"IpAddress",
":",
"session",
".",
"IpAddress",
",",
"UserAgent",
":",
"session",
".",
"UserAgent",
",",
"Locale",
":",
"session",
".",
"Locale",
",",
"}",
")",
"\n",
"}",
"\n",
"}"
] |
// SetSession should be called after successful authentication.
|
[
"SetSession",
"should",
"be",
"called",
"after",
"successful",
"authentication",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/session_manager.go#L274-L296
|
21,277
|
vmware/govmomi
|
simulator/session_manager.go
|
postEvent
|
func (c *Context) postEvent(events ...types.BaseEvent) {
m := Map.EventManager()
c.WithLock(m, func() {
for _, event := range events {
m.PostEvent(c, &types.PostEvent{EventToPost: event})
}
})
}
|
go
|
func (c *Context) postEvent(events ...types.BaseEvent) {
m := Map.EventManager()
c.WithLock(m, func() {
for _, event := range events {
m.PostEvent(c, &types.PostEvent{EventToPost: event})
}
})
}
|
[
"func",
"(",
"c",
"*",
"Context",
")",
"postEvent",
"(",
"events",
"...",
"types",
".",
"BaseEvent",
")",
"{",
"m",
":=",
"Map",
".",
"EventManager",
"(",
")",
"\n",
"c",
".",
"WithLock",
"(",
"m",
",",
"func",
"(",
")",
"{",
"for",
"_",
",",
"event",
":=",
"range",
"events",
"{",
"m",
".",
"PostEvent",
"(",
"c",
",",
"&",
"types",
".",
"PostEvent",
"{",
"EventToPost",
":",
"event",
"}",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] |
// postEvent wraps EventManager.PostEvent for internal use, with a lock on the EventManager.
|
[
"postEvent",
"wraps",
"EventManager",
".",
"PostEvent",
"for",
"internal",
"use",
"with",
"a",
"lock",
"on",
"the",
"EventManager",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/session_manager.go#L309-L316
|
21,278
|
vmware/govmomi
|
simulator/session_manager.go
|
Put
|
func (s *Session) Put(item mo.Reference) mo.Reference {
ref := item.Reference()
if ref.Value == "" {
ref.Value = fmt.Sprintf("session[%s]%s", s.Key, uuid.New())
}
s.Registry.setReference(item, ref)
return s.Registry.Put(item)
}
|
go
|
func (s *Session) Put(item mo.Reference) mo.Reference {
ref := item.Reference()
if ref.Value == "" {
ref.Value = fmt.Sprintf("session[%s]%s", s.Key, uuid.New())
}
s.Registry.setReference(item, ref)
return s.Registry.Put(item)
}
|
[
"func",
"(",
"s",
"*",
"Session",
")",
"Put",
"(",
"item",
"mo",
".",
"Reference",
")",
"mo",
".",
"Reference",
"{",
"ref",
":=",
"item",
".",
"Reference",
"(",
")",
"\n",
"if",
"ref",
".",
"Value",
"==",
"\"",
"\"",
"{",
"ref",
".",
"Value",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"s",
".",
"Key",
",",
"uuid",
".",
"New",
"(",
")",
")",
"\n",
"}",
"\n",
"s",
".",
"Registry",
".",
"setReference",
"(",
"item",
",",
"ref",
")",
"\n",
"return",
"s",
".",
"Registry",
".",
"Put",
"(",
"item",
")",
"\n",
"}"
] |
// Put wraps Registry.Put, setting the moref value to include the session key.
|
[
"Put",
"wraps",
"Registry",
".",
"Put",
"setting",
"the",
"moref",
"value",
"to",
"include",
"the",
"session",
"key",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/session_manager.go#L325-L332
|
21,279
|
vmware/govmomi
|
simulator/session_manager.go
|
Get
|
func (s *Session) Get(ref types.ManagedObjectReference) mo.Reference {
obj := s.Registry.Get(ref)
if obj != nil {
return obj
}
// Return a session "view" of certain singleton objects
switch ref.Type {
case "SessionManager":
// Clone SessionManager so the PropertyCollector can properly report CurrentSession
m := *Map.SessionManager()
m.CurrentSession = &s.UserSession
// TODO: we could maintain SessionList as part of the SessionManager singleton
for _, session := range m.sessions {
m.SessionList = append(m.SessionList, session.UserSession)
}
return &m
case "PropertyCollector":
if ref == Map.content().PropertyCollector {
return s.Put(NewPropertyCollector(ref))
}
}
return Map.Get(ref)
}
|
go
|
func (s *Session) Get(ref types.ManagedObjectReference) mo.Reference {
obj := s.Registry.Get(ref)
if obj != nil {
return obj
}
// Return a session "view" of certain singleton objects
switch ref.Type {
case "SessionManager":
// Clone SessionManager so the PropertyCollector can properly report CurrentSession
m := *Map.SessionManager()
m.CurrentSession = &s.UserSession
// TODO: we could maintain SessionList as part of the SessionManager singleton
for _, session := range m.sessions {
m.SessionList = append(m.SessionList, session.UserSession)
}
return &m
case "PropertyCollector":
if ref == Map.content().PropertyCollector {
return s.Put(NewPropertyCollector(ref))
}
}
return Map.Get(ref)
}
|
[
"func",
"(",
"s",
"*",
"Session",
")",
"Get",
"(",
"ref",
"types",
".",
"ManagedObjectReference",
")",
"mo",
".",
"Reference",
"{",
"obj",
":=",
"s",
".",
"Registry",
".",
"Get",
"(",
"ref",
")",
"\n",
"if",
"obj",
"!=",
"nil",
"{",
"return",
"obj",
"\n",
"}",
"\n\n",
"// Return a session \"view\" of certain singleton objects",
"switch",
"ref",
".",
"Type",
"{",
"case",
"\"",
"\"",
":",
"// Clone SessionManager so the PropertyCollector can properly report CurrentSession",
"m",
":=",
"*",
"Map",
".",
"SessionManager",
"(",
")",
"\n",
"m",
".",
"CurrentSession",
"=",
"&",
"s",
".",
"UserSession",
"\n\n",
"// TODO: we could maintain SessionList as part of the SessionManager singleton",
"for",
"_",
",",
"session",
":=",
"range",
"m",
".",
"sessions",
"{",
"m",
".",
"SessionList",
"=",
"append",
"(",
"m",
".",
"SessionList",
",",
"session",
".",
"UserSession",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"m",
"\n",
"case",
"\"",
"\"",
":",
"if",
"ref",
"==",
"Map",
".",
"content",
"(",
")",
".",
"PropertyCollector",
"{",
"return",
"s",
".",
"Put",
"(",
"NewPropertyCollector",
"(",
"ref",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"Map",
".",
"Get",
"(",
"ref",
")",
"\n",
"}"
] |
// Get wraps Registry.Get, session-izing singleton objects such as SessionManager and the root PropertyCollector.
|
[
"Get",
"wraps",
"Registry",
".",
"Get",
"session",
"-",
"izing",
"singleton",
"objects",
"such",
"as",
"SessionManager",
"and",
"the",
"root",
"PropertyCollector",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/simulator/session_manager.go#L335-L361
|
21,280
|
vmware/govmomi
|
object/file_manager.go
|
DeleteDatastoreFile
|
func (f FileManager) DeleteDatastoreFile(ctx context.Context, name string, dc *Datacenter) (*Task, error) {
req := types.DeleteDatastoreFile_Task{
This: f.Reference(),
Name: name,
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
res, err := methods.DeleteDatastoreFile_Task(ctx, f.c, &req)
if err != nil {
return nil, err
}
return NewTask(f.c, res.Returnval), nil
}
|
go
|
func (f FileManager) DeleteDatastoreFile(ctx context.Context, name string, dc *Datacenter) (*Task, error) {
req := types.DeleteDatastoreFile_Task{
This: f.Reference(),
Name: name,
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
res, err := methods.DeleteDatastoreFile_Task(ctx, f.c, &req)
if err != nil {
return nil, err
}
return NewTask(f.c, res.Returnval), nil
}
|
[
"func",
"(",
"f",
"FileManager",
")",
"DeleteDatastoreFile",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"dc",
"*",
"Datacenter",
")",
"(",
"*",
"Task",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"DeleteDatastoreFile_Task",
"{",
"This",
":",
"f",
".",
"Reference",
"(",
")",
",",
"Name",
":",
"name",
",",
"}",
"\n\n",
"if",
"dc",
"!=",
"nil",
"{",
"ref",
":=",
"dc",
".",
"Reference",
"(",
")",
"\n",
"req",
".",
"Datacenter",
"=",
"&",
"ref",
"\n",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"DeleteDatastoreFile_Task",
"(",
"ctx",
",",
"f",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"NewTask",
"(",
"f",
".",
"c",
",",
"res",
".",
"Returnval",
")",
",",
"nil",
"\n",
"}"
] |
// DeleteDatastoreFile deletes the specified file or folder from the datastore.
|
[
"DeleteDatastoreFile",
"deletes",
"the",
"specified",
"file",
"or",
"folder",
"from",
"the",
"datastore",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/file_manager.go#L66-L83
|
21,281
|
vmware/govmomi
|
object/file_manager.go
|
MakeDirectory
|
func (f FileManager) MakeDirectory(ctx context.Context, name string, dc *Datacenter, createParentDirectories bool) error {
req := types.MakeDirectory{
This: f.Reference(),
Name: name,
CreateParentDirectories: types.NewBool(createParentDirectories),
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
_, err := methods.MakeDirectory(ctx, f.c, &req)
return err
}
|
go
|
func (f FileManager) MakeDirectory(ctx context.Context, name string, dc *Datacenter, createParentDirectories bool) error {
req := types.MakeDirectory{
This: f.Reference(),
Name: name,
CreateParentDirectories: types.NewBool(createParentDirectories),
}
if dc != nil {
ref := dc.Reference()
req.Datacenter = &ref
}
_, err := methods.MakeDirectory(ctx, f.c, &req)
return err
}
|
[
"func",
"(",
"f",
"FileManager",
")",
"MakeDirectory",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"dc",
"*",
"Datacenter",
",",
"createParentDirectories",
"bool",
")",
"error",
"{",
"req",
":=",
"types",
".",
"MakeDirectory",
"{",
"This",
":",
"f",
".",
"Reference",
"(",
")",
",",
"Name",
":",
"name",
",",
"CreateParentDirectories",
":",
"types",
".",
"NewBool",
"(",
"createParentDirectories",
")",
",",
"}",
"\n\n",
"if",
"dc",
"!=",
"nil",
"{",
"ref",
":=",
"dc",
".",
"Reference",
"(",
")",
"\n",
"req",
".",
"Datacenter",
"=",
"&",
"ref",
"\n",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"MakeDirectory",
"(",
"ctx",
",",
"f",
".",
"c",
",",
"&",
"req",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// MakeDirectory creates a folder using the specified name.
|
[
"MakeDirectory",
"creates",
"a",
"folder",
"using",
"the",
"specified",
"name",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/file_manager.go#L86-L100
|
21,282
|
vmware/govmomi
|
event/manager.go
|
EventCategory
|
func (m Manager) EventCategory(ctx context.Context, event types.BaseEvent) (string, error) {
// Most of the event details are included in the Event.FullFormattedMessage, but the category
// is only available via the EventManager description.eventInfo property. The value of this
// property is static, so we fetch and once and cache.
eventCategory, err := m.eventCategoryMap(ctx)
if err != nil {
return "", err
}
switch e := event.(type) {
case *types.EventEx:
if e.Severity == "" {
return "info", nil
}
return e.Severity, nil
}
class := reflect.TypeOf(event).Elem().Name()
return eventCategory[class], nil
}
|
go
|
func (m Manager) EventCategory(ctx context.Context, event types.BaseEvent) (string, error) {
// Most of the event details are included in the Event.FullFormattedMessage, but the category
// is only available via the EventManager description.eventInfo property. The value of this
// property is static, so we fetch and once and cache.
eventCategory, err := m.eventCategoryMap(ctx)
if err != nil {
return "", err
}
switch e := event.(type) {
case *types.EventEx:
if e.Severity == "" {
return "info", nil
}
return e.Severity, nil
}
class := reflect.TypeOf(event).Elem().Name()
return eventCategory[class], nil
}
|
[
"func",
"(",
"m",
"Manager",
")",
"EventCategory",
"(",
"ctx",
"context",
".",
"Context",
",",
"event",
"types",
".",
"BaseEvent",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Most of the event details are included in the Event.FullFormattedMessage, but the category",
"// is only available via the EventManager description.eventInfo property. The value of this",
"// property is static, so we fetch and once and cache.",
"eventCategory",
",",
"err",
":=",
"m",
".",
"eventCategoryMap",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"switch",
"e",
":=",
"event",
".",
"(",
"type",
")",
"{",
"case",
"*",
"types",
".",
"EventEx",
":",
"if",
"e",
".",
"Severity",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"return",
"e",
".",
"Severity",
",",
"nil",
"\n",
"}",
"\n\n",
"class",
":=",
"reflect",
".",
"TypeOf",
"(",
"event",
")",
".",
"Elem",
"(",
")",
".",
"Name",
"(",
")",
"\n\n",
"return",
"eventCategory",
"[",
"class",
"]",
",",
"nil",
"\n",
"}"
] |
// EventCategory returns the category for an event, such as "info" or "error" for example.
|
[
"EventCategory",
"returns",
"the",
"category",
"for",
"an",
"event",
"such",
"as",
"info",
"or",
"error",
"for",
"example",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/event/manager.go#L152-L172
|
21,283
|
vmware/govmomi
|
toolbox/hgfs/protocol.go
|
errorStatus
|
func errorStatus(err error) uint32 {
if x, ok := err.(*Status); ok {
return x.Code
}
switch {
case os.IsNotExist(err):
return StatusNoSuchFileOrDir
case os.IsExist(err):
return StatusFileExists
case os.IsPermission(err):
return StatusOperationNotPermitted
}
return StatusGenericError
}
|
go
|
func errorStatus(err error) uint32 {
if x, ok := err.(*Status); ok {
return x.Code
}
switch {
case os.IsNotExist(err):
return StatusNoSuchFileOrDir
case os.IsExist(err):
return StatusFileExists
case os.IsPermission(err):
return StatusOperationNotPermitted
}
return StatusGenericError
}
|
[
"func",
"errorStatus",
"(",
"err",
"error",
")",
"uint32",
"{",
"if",
"x",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"Status",
")",
";",
"ok",
"{",
"return",
"x",
".",
"Code",
"\n",
"}",
"\n\n",
"switch",
"{",
"case",
"os",
".",
"IsNotExist",
"(",
"err",
")",
":",
"return",
"StatusNoSuchFileOrDir",
"\n",
"case",
"os",
".",
"IsExist",
"(",
"err",
")",
":",
"return",
"StatusFileExists",
"\n",
"case",
"os",
".",
"IsPermission",
"(",
"err",
")",
":",
"return",
"StatusOperationNotPermitted",
"\n",
"}",
"\n\n",
"return",
"StatusGenericError",
"\n",
"}"
] |
// errorStatus maps the given error type to a status code
|
[
"errorStatus",
"maps",
"the",
"given",
"error",
"type",
"to",
"a",
"status",
"code"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/protocol.go#L178-L193
|
21,284
|
vmware/govmomi
|
toolbox/hgfs/protocol.go
|
Reply
|
func (r *Packet) Reply(payload interface{}, err error) ([]byte, error) {
p := new(Packet)
status := uint32(StatusSuccess)
if err != nil {
status = errorStatus(err)
} else {
p.Payload, err = MarshalBinary(payload)
if err != nil {
return nil, err
}
}
p.Header = Header{
Version: HeaderVersion,
Dummy: OpNewHeader,
PacketSize: headerSize + uint32(len(p.Payload)),
HeaderSize: headerSize,
RequestID: r.RequestID,
Op: r.Op,
Status: status,
Flags: PacketFlagReply,
Information: 0,
SessionID: r.SessionID,
}
if Trace {
rc := "OK"
if err != nil {
rc = err.Error()
}
fmt.Fprintf(os.Stderr, "[hgfs] response %#v [%s]\n", p.Header, rc)
} else if err != nil {
log.Printf("[hgfs] op=%d error: %s", r.Op, err)
}
return p.MarshalBinary()
}
|
go
|
func (r *Packet) Reply(payload interface{}, err error) ([]byte, error) {
p := new(Packet)
status := uint32(StatusSuccess)
if err != nil {
status = errorStatus(err)
} else {
p.Payload, err = MarshalBinary(payload)
if err != nil {
return nil, err
}
}
p.Header = Header{
Version: HeaderVersion,
Dummy: OpNewHeader,
PacketSize: headerSize + uint32(len(p.Payload)),
HeaderSize: headerSize,
RequestID: r.RequestID,
Op: r.Op,
Status: status,
Flags: PacketFlagReply,
Information: 0,
SessionID: r.SessionID,
}
if Trace {
rc := "OK"
if err != nil {
rc = err.Error()
}
fmt.Fprintf(os.Stderr, "[hgfs] response %#v [%s]\n", p.Header, rc)
} else if err != nil {
log.Printf("[hgfs] op=%d error: %s", r.Op, err)
}
return p.MarshalBinary()
}
|
[
"func",
"(",
"r",
"*",
"Packet",
")",
"Reply",
"(",
"payload",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"p",
":=",
"new",
"(",
"Packet",
")",
"\n\n",
"status",
":=",
"uint32",
"(",
"StatusSuccess",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"status",
"=",
"errorStatus",
"(",
"err",
")",
"\n",
"}",
"else",
"{",
"p",
".",
"Payload",
",",
"err",
"=",
"MarshalBinary",
"(",
"payload",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"p",
".",
"Header",
"=",
"Header",
"{",
"Version",
":",
"HeaderVersion",
",",
"Dummy",
":",
"OpNewHeader",
",",
"PacketSize",
":",
"headerSize",
"+",
"uint32",
"(",
"len",
"(",
"p",
".",
"Payload",
")",
")",
",",
"HeaderSize",
":",
"headerSize",
",",
"RequestID",
":",
"r",
".",
"RequestID",
",",
"Op",
":",
"r",
".",
"Op",
",",
"Status",
":",
"status",
",",
"Flags",
":",
"PacketFlagReply",
",",
"Information",
":",
"0",
",",
"SessionID",
":",
"r",
".",
"SessionID",
",",
"}",
"\n\n",
"if",
"Trace",
"{",
"rc",
":=",
"\"",
"\"",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"rc",
"=",
"err",
".",
"Error",
"(",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"p",
".",
"Header",
",",
"rc",
")",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"r",
".",
"Op",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"p",
".",
"MarshalBinary",
"(",
")",
"\n",
"}"
] |
// Reply composes a new Packet with the given payload or error
|
[
"Reply",
"composes",
"a",
"new",
"Packet",
"with",
"the",
"given",
"payload",
"or",
"error"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/protocol.go#L263-L301
|
21,285
|
vmware/govmomi
|
toolbox/hgfs/protocol.go
|
FromString
|
func (f *FileName) FromString(name string) {
name = strings.TrimPrefix(name, "/")
cp := strings.Split(name, "/")
cp = append([]string{serverPolicyRootShareName}, cp...)
f.Name = strings.Join(cp, "\x00")
f.Length = uint32(len(f.Name))
}
|
go
|
func (f *FileName) FromString(name string) {
name = strings.TrimPrefix(name, "/")
cp := strings.Split(name, "/")
cp = append([]string{serverPolicyRootShareName}, cp...)
f.Name = strings.Join(cp, "\x00")
f.Length = uint32(len(f.Name))
}
|
[
"func",
"(",
"f",
"*",
"FileName",
")",
"FromString",
"(",
"name",
"string",
")",
"{",
"name",
"=",
"strings",
".",
"TrimPrefix",
"(",
"name",
",",
"\"",
"\"",
")",
"\n\n",
"cp",
":=",
"strings",
".",
"Split",
"(",
"name",
",",
"\"",
"\"",
")",
"\n\n",
"cp",
"=",
"append",
"(",
"[",
"]",
"string",
"{",
"serverPolicyRootShareName",
"}",
",",
"cp",
"...",
")",
"\n\n",
"f",
".",
"Name",
"=",
"strings",
".",
"Join",
"(",
"cp",
",",
"\"",
"\\x00",
"\"",
")",
"\n",
"f",
".",
"Length",
"=",
"uint32",
"(",
"len",
"(",
"f",
".",
"Name",
")",
")",
"\n",
"}"
] |
// FromString converts name to a FileName
|
[
"FromString",
"converts",
"name",
"to",
"a",
"FileName"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/protocol.go#L515-L524
|
21,286
|
vmware/govmomi
|
toolbox/hgfs/protocol.go
|
Path
|
func (f *FileName) Path() string {
cp := strings.Split(f.Name, "\x00")
if len(cp) == 0 || cp[0] != serverPolicyRootShareName {
return "" // TODO: not happening until if/when we handle Windows shares
}
cp[0] = ""
return strings.Join(cp, "/")
}
|
go
|
func (f *FileName) Path() string {
cp := strings.Split(f.Name, "\x00")
if len(cp) == 0 || cp[0] != serverPolicyRootShareName {
return "" // TODO: not happening until if/when we handle Windows shares
}
cp[0] = ""
return strings.Join(cp, "/")
}
|
[
"func",
"(",
"f",
"*",
"FileName",
")",
"Path",
"(",
")",
"string",
"{",
"cp",
":=",
"strings",
".",
"Split",
"(",
"f",
".",
"Name",
",",
"\"",
"\\x00",
"\"",
")",
"\n\n",
"if",
"len",
"(",
"cp",
")",
"==",
"0",
"||",
"cp",
"[",
"0",
"]",
"!=",
"serverPolicyRootShareName",
"{",
"return",
"\"",
"\"",
"// TODO: not happening until if/when we handle Windows shares",
"\n",
"}",
"\n\n",
"cp",
"[",
"0",
"]",
"=",
"\"",
"\"",
"\n\n",
"return",
"strings",
".",
"Join",
"(",
"cp",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// Path converts FileName to a string
|
[
"Path",
"converts",
"FileName",
"to",
"a",
"string"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/protocol.go#L527-L537
|
21,287
|
vmware/govmomi
|
toolbox/hgfs/protocol.go
|
FromString
|
func (f *FileNameV3) FromString(name string) {
p := new(FileName)
p.FromString(name)
f.Name = p.Name
f.Length = p.Length
}
|
go
|
func (f *FileNameV3) FromString(name string) {
p := new(FileName)
p.FromString(name)
f.Name = p.Name
f.Length = p.Length
}
|
[
"func",
"(",
"f",
"*",
"FileNameV3",
")",
"FromString",
"(",
"name",
"string",
")",
"{",
"p",
":=",
"new",
"(",
"FileName",
")",
"\n",
"p",
".",
"FromString",
"(",
"name",
")",
"\n",
"f",
".",
"Name",
"=",
"p",
".",
"Name",
"\n",
"f",
".",
"Length",
"=",
"p",
".",
"Length",
"\n",
"}"
] |
// FromString converts name to a FileNameV3
|
[
"FromString",
"converts",
"name",
"to",
"a",
"FileNameV3"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/protocol.go#L579-L584
|
21,288
|
vmware/govmomi
|
toolbox/hgfs/protocol.go
|
Path
|
func (f *FileNameV3) Path() string {
return (&FileName{Name: f.Name, Length: f.Length}).Path()
}
|
go
|
func (f *FileNameV3) Path() string {
return (&FileName{Name: f.Name, Length: f.Length}).Path()
}
|
[
"func",
"(",
"f",
"*",
"FileNameV3",
")",
"Path",
"(",
")",
"string",
"{",
"return",
"(",
"&",
"FileName",
"{",
"Name",
":",
"f",
".",
"Name",
",",
"Length",
":",
"f",
".",
"Length",
"}",
")",
".",
"Path",
"(",
")",
"\n",
"}"
] |
// Path converts FileNameV3 to a string
|
[
"Path",
"converts",
"FileNameV3",
"to",
"a",
"string"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/toolbox/hgfs/protocol.go#L587-L589
|
21,289
|
vmware/govmomi
|
sts/simulator/simulator.go
|
New
|
func New(u *url.URL, settings []vim.BaseOptionValue) (string, http.Handler) {
for i := range settings {
setting := settings[i].GetOptionValue()
if setting.Key == "config.vpxd.sso.sts.uri" {
endpoint, _ := url.Parse(setting.Value.(string))
endpoint.Host = u.Host
setting.Value = endpoint.String()
settings[i] = setting
return endpoint.Path, new(handler)
}
}
return "", nil
}
|
go
|
func New(u *url.URL, settings []vim.BaseOptionValue) (string, http.Handler) {
for i := range settings {
setting := settings[i].GetOptionValue()
if setting.Key == "config.vpxd.sso.sts.uri" {
endpoint, _ := url.Parse(setting.Value.(string))
endpoint.Host = u.Host
setting.Value = endpoint.String()
settings[i] = setting
return endpoint.Path, new(handler)
}
}
return "", nil
}
|
[
"func",
"New",
"(",
"u",
"*",
"url",
".",
"URL",
",",
"settings",
"[",
"]",
"vim",
".",
"BaseOptionValue",
")",
"(",
"string",
",",
"http",
".",
"Handler",
")",
"{",
"for",
"i",
":=",
"range",
"settings",
"{",
"setting",
":=",
"settings",
"[",
"i",
"]",
".",
"GetOptionValue",
"(",
")",
"\n",
"if",
"setting",
".",
"Key",
"==",
"\"",
"\"",
"{",
"endpoint",
",",
"_",
":=",
"url",
".",
"Parse",
"(",
"setting",
".",
"Value",
".",
"(",
"string",
")",
")",
"\n",
"endpoint",
".",
"Host",
"=",
"u",
".",
"Host",
"\n",
"setting",
".",
"Value",
"=",
"endpoint",
".",
"String",
"(",
")",
"\n",
"settings",
"[",
"i",
"]",
"=",
"setting",
"\n",
"return",
"endpoint",
".",
"Path",
",",
"new",
"(",
"handler",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}"
] |
// New creates an STS simulator and configures the simulator endpoint in the given settings.
// The path returned is that of the settings "config.vpxd.sso.sts.uri" property.
|
[
"New",
"creates",
"an",
"STS",
"simulator",
"and",
"configures",
"the",
"simulator",
"endpoint",
"in",
"the",
"given",
"settings",
".",
"The",
"path",
"returned",
"is",
"that",
"of",
"the",
"settings",
"config",
".",
"vpxd",
".",
"sso",
".",
"sts",
".",
"uri",
"property",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/sts/simulator/simulator.go#L34-L46
|
21,290
|
vmware/govmomi
|
sts/simulator/simulator.go
|
ServeHTTP
|
func (s *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
action := r.Header.Get("SOAPAction")
env := soap.Envelope{}
now := time.Now()
lifetime := &internal.Lifetime{
Created: now.Format(internal.Time),
Expires: now.Add(5 * time.Minute).Format(internal.Time),
}
switch path.Base(action) {
case "Issue":
body := internal.RequestSecurityTokenBody{
Res: &internal.RequestSecurityTokenResponseCollection{
RequestSecurityTokenResponse: internal.RequestSecurityTokenResponse{
RequestedSecurityToken: internal.RequestedSecurityToken{
Assertion: token,
},
Lifetime: lifetime,
},
},
}
env.Body = body
case "Renew":
body := internal.RenewSecurityTokenBody{
Res: &internal.RequestSecurityTokenResponse{
RequestedSecurityToken: internal.RequestedSecurityToken{
Assertion: token,
},
Lifetime: lifetime,
},
}
env.Body = body
default:
log.Printf("sts: unsupported action=%s", action)
w.WriteHeader(http.StatusNotFound)
return
}
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, internal.Marshal(env))
}
|
go
|
func (s *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
action := r.Header.Get("SOAPAction")
env := soap.Envelope{}
now := time.Now()
lifetime := &internal.Lifetime{
Created: now.Format(internal.Time),
Expires: now.Add(5 * time.Minute).Format(internal.Time),
}
switch path.Base(action) {
case "Issue":
body := internal.RequestSecurityTokenBody{
Res: &internal.RequestSecurityTokenResponseCollection{
RequestSecurityTokenResponse: internal.RequestSecurityTokenResponse{
RequestedSecurityToken: internal.RequestedSecurityToken{
Assertion: token,
},
Lifetime: lifetime,
},
},
}
env.Body = body
case "Renew":
body := internal.RenewSecurityTokenBody{
Res: &internal.RequestSecurityTokenResponse{
RequestedSecurityToken: internal.RequestedSecurityToken{
Assertion: token,
},
Lifetime: lifetime,
},
}
env.Body = body
default:
log.Printf("sts: unsupported action=%s", action)
w.WriteHeader(http.StatusNotFound)
return
}
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, internal.Marshal(env))
}
|
[
"func",
"(",
"s",
"*",
"handler",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"action",
":=",
"r",
".",
"Header",
".",
"Get",
"(",
"\"",
"\"",
")",
"\n",
"env",
":=",
"soap",
".",
"Envelope",
"{",
"}",
"\n",
"now",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"lifetime",
":=",
"&",
"internal",
".",
"Lifetime",
"{",
"Created",
":",
"now",
".",
"Format",
"(",
"internal",
".",
"Time",
")",
",",
"Expires",
":",
"now",
".",
"Add",
"(",
"5",
"*",
"time",
".",
"Minute",
")",
".",
"Format",
"(",
"internal",
".",
"Time",
")",
",",
"}",
"\n\n",
"switch",
"path",
".",
"Base",
"(",
"action",
")",
"{",
"case",
"\"",
"\"",
":",
"body",
":=",
"internal",
".",
"RequestSecurityTokenBody",
"{",
"Res",
":",
"&",
"internal",
".",
"RequestSecurityTokenResponseCollection",
"{",
"RequestSecurityTokenResponse",
":",
"internal",
".",
"RequestSecurityTokenResponse",
"{",
"RequestedSecurityToken",
":",
"internal",
".",
"RequestedSecurityToken",
"{",
"Assertion",
":",
"token",
",",
"}",
",",
"Lifetime",
":",
"lifetime",
",",
"}",
",",
"}",
",",
"}",
"\n",
"env",
".",
"Body",
"=",
"body",
"\n",
"case",
"\"",
"\"",
":",
"body",
":=",
"internal",
".",
"RenewSecurityTokenBody",
"{",
"Res",
":",
"&",
"internal",
".",
"RequestSecurityTokenResponse",
"{",
"RequestedSecurityToken",
":",
"internal",
".",
"RequestedSecurityToken",
"{",
"Assertion",
":",
"token",
",",
"}",
",",
"Lifetime",
":",
"lifetime",
",",
"}",
",",
"}",
"\n",
"env",
".",
"Body",
"=",
"body",
"\n",
"default",
":",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"action",
")",
"\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusNotFound",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"w",
".",
"WriteHeader",
"(",
"http",
".",
"StatusOK",
")",
"\n",
"fmt",
".",
"Fprint",
"(",
"w",
",",
"internal",
".",
"Marshal",
"(",
"env",
")",
")",
"\n",
"}"
] |
// ServeHTTP handles STS requests.
|
[
"ServeHTTP",
"handles",
"STS",
"requests",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/sts/simulator/simulator.go#L51-L91
|
21,291
|
vmware/govmomi
|
object/virtual_machine.go
|
Device
|
func (v VirtualMachine) Device(ctx context.Context) (VirtualDeviceList, error) {
var o mo.VirtualMachine
err := v.Properties(ctx, v.Reference(), []string{"config.hardware.device", "summary.runtime.connectionState"}, &o)
if err != nil {
return nil, err
}
// Quoting the SDK doc:
// The virtual machine configuration is not guaranteed to be available.
// For example, the configuration information would be unavailable if the server
// is unable to access the virtual machine files on disk, and is often also unavailable
// during the initial phases of virtual machine creation.
if o.Config == nil {
return nil, fmt.Errorf("%s Config is not available, connectionState=%s",
v.Reference(), o.Summary.Runtime.ConnectionState)
}
return VirtualDeviceList(o.Config.Hardware.Device), nil
}
|
go
|
func (v VirtualMachine) Device(ctx context.Context) (VirtualDeviceList, error) {
var o mo.VirtualMachine
err := v.Properties(ctx, v.Reference(), []string{"config.hardware.device", "summary.runtime.connectionState"}, &o)
if err != nil {
return nil, err
}
// Quoting the SDK doc:
// The virtual machine configuration is not guaranteed to be available.
// For example, the configuration information would be unavailable if the server
// is unable to access the virtual machine files on disk, and is often also unavailable
// during the initial phases of virtual machine creation.
if o.Config == nil {
return nil, fmt.Errorf("%s Config is not available, connectionState=%s",
v.Reference(), o.Summary.Runtime.ConnectionState)
}
return VirtualDeviceList(o.Config.Hardware.Device), nil
}
|
[
"func",
"(",
"v",
"VirtualMachine",
")",
"Device",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"VirtualDeviceList",
",",
"error",
")",
"{",
"var",
"o",
"mo",
".",
"VirtualMachine",
"\n\n",
"err",
":=",
"v",
".",
"Properties",
"(",
"ctx",
",",
"v",
".",
"Reference",
"(",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"&",
"o",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Quoting the SDK doc:",
"// The virtual machine configuration is not guaranteed to be available.",
"// For example, the configuration information would be unavailable if the server",
"// is unable to access the virtual machine files on disk, and is often also unavailable",
"// during the initial phases of virtual machine creation.",
"if",
"o",
".",
"Config",
"==",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"v",
".",
"Reference",
"(",
")",
",",
"o",
".",
"Summary",
".",
"Runtime",
".",
"ConnectionState",
")",
"\n",
"}",
"\n\n",
"return",
"VirtualDeviceList",
"(",
"o",
".",
"Config",
".",
"Hardware",
".",
"Device",
")",
",",
"nil",
"\n",
"}"
] |
// Device returns the VirtualMachine's config.hardware.device property.
|
[
"Device",
"returns",
"the",
"VirtualMachine",
"s",
"config",
".",
"hardware",
".",
"device",
"property",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L345-L364
|
21,292
|
vmware/govmomi
|
object/virtual_machine.go
|
AddDevice
|
func (v VirtualMachine) AddDevice(ctx context.Context, device ...types.BaseVirtualDevice) error {
return v.configureDevice(ctx, types.VirtualDeviceConfigSpecOperationAdd, types.VirtualDeviceConfigSpecFileOperationCreate, device...)
}
|
go
|
func (v VirtualMachine) AddDevice(ctx context.Context, device ...types.BaseVirtualDevice) error {
return v.configureDevice(ctx, types.VirtualDeviceConfigSpecOperationAdd, types.VirtualDeviceConfigSpecFileOperationCreate, device...)
}
|
[
"func",
"(",
"v",
"VirtualMachine",
")",
"AddDevice",
"(",
"ctx",
"context",
".",
"Context",
",",
"device",
"...",
"types",
".",
"BaseVirtualDevice",
")",
"error",
"{",
"return",
"v",
".",
"configureDevice",
"(",
"ctx",
",",
"types",
".",
"VirtualDeviceConfigSpecOperationAdd",
",",
"types",
".",
"VirtualDeviceConfigSpecFileOperationCreate",
",",
"device",
"...",
")",
"\n",
"}"
] |
// AddDevice adds the given devices to the VirtualMachine
|
[
"AddDevice",
"adds",
"the",
"given",
"devices",
"to",
"the",
"VirtualMachine"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L435-L437
|
21,293
|
vmware/govmomi
|
object/virtual_machine.go
|
RemoveDevice
|
func (v VirtualMachine) RemoveDevice(ctx context.Context, keepFiles bool, device ...types.BaseVirtualDevice) error {
fop := types.VirtualDeviceConfigSpecFileOperationDestroy
if keepFiles {
fop = ""
}
return v.configureDevice(ctx, types.VirtualDeviceConfigSpecOperationRemove, fop, device...)
}
|
go
|
func (v VirtualMachine) RemoveDevice(ctx context.Context, keepFiles bool, device ...types.BaseVirtualDevice) error {
fop := types.VirtualDeviceConfigSpecFileOperationDestroy
if keepFiles {
fop = ""
}
return v.configureDevice(ctx, types.VirtualDeviceConfigSpecOperationRemove, fop, device...)
}
|
[
"func",
"(",
"v",
"VirtualMachine",
")",
"RemoveDevice",
"(",
"ctx",
"context",
".",
"Context",
",",
"keepFiles",
"bool",
",",
"device",
"...",
"types",
".",
"BaseVirtualDevice",
")",
"error",
"{",
"fop",
":=",
"types",
".",
"VirtualDeviceConfigSpecFileOperationDestroy",
"\n",
"if",
"keepFiles",
"{",
"fop",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"v",
".",
"configureDevice",
"(",
"ctx",
",",
"types",
".",
"VirtualDeviceConfigSpecOperationRemove",
",",
"fop",
",",
"device",
"...",
")",
"\n",
"}"
] |
// RemoveDevice removes the given devices on the VirtualMachine
|
[
"RemoveDevice",
"removes",
"the",
"given",
"devices",
"on",
"the",
"VirtualMachine"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L445-L451
|
21,294
|
vmware/govmomi
|
object/virtual_machine.go
|
BootOptions
|
func (v VirtualMachine) BootOptions(ctx context.Context) (*types.VirtualMachineBootOptions, error) {
var o mo.VirtualMachine
err := v.Properties(ctx, v.Reference(), []string{"config.bootOptions"}, &o)
if err != nil {
return nil, err
}
return o.Config.BootOptions, nil
}
|
go
|
func (v VirtualMachine) BootOptions(ctx context.Context) (*types.VirtualMachineBootOptions, error) {
var o mo.VirtualMachine
err := v.Properties(ctx, v.Reference(), []string{"config.bootOptions"}, &o)
if err != nil {
return nil, err
}
return o.Config.BootOptions, nil
}
|
[
"func",
"(",
"v",
"VirtualMachine",
")",
"BootOptions",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"types",
".",
"VirtualMachineBootOptions",
",",
"error",
")",
"{",
"var",
"o",
"mo",
".",
"VirtualMachine",
"\n\n",
"err",
":=",
"v",
".",
"Properties",
"(",
"ctx",
",",
"v",
".",
"Reference",
"(",
")",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"&",
"o",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"o",
".",
"Config",
".",
"BootOptions",
",",
"nil",
"\n",
"}"
] |
// BootOptions returns the VirtualMachine's config.bootOptions property.
|
[
"BootOptions",
"returns",
"the",
"VirtualMachine",
"s",
"config",
".",
"bootOptions",
"property",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L454-L463
|
21,295
|
vmware/govmomi
|
object/virtual_machine.go
|
SetBootOptions
|
func (v VirtualMachine) SetBootOptions(ctx context.Context, options *types.VirtualMachineBootOptions) error {
spec := types.VirtualMachineConfigSpec{}
spec.BootOptions = options
task, err := v.Reconfigure(ctx, spec)
if err != nil {
return err
}
return task.Wait(ctx)
}
|
go
|
func (v VirtualMachine) SetBootOptions(ctx context.Context, options *types.VirtualMachineBootOptions) error {
spec := types.VirtualMachineConfigSpec{}
spec.BootOptions = options
task, err := v.Reconfigure(ctx, spec)
if err != nil {
return err
}
return task.Wait(ctx)
}
|
[
"func",
"(",
"v",
"VirtualMachine",
")",
"SetBootOptions",
"(",
"ctx",
"context",
".",
"Context",
",",
"options",
"*",
"types",
".",
"VirtualMachineBootOptions",
")",
"error",
"{",
"spec",
":=",
"types",
".",
"VirtualMachineConfigSpec",
"{",
"}",
"\n\n",
"spec",
".",
"BootOptions",
"=",
"options",
"\n\n",
"task",
",",
"err",
":=",
"v",
".",
"Reconfigure",
"(",
"ctx",
",",
"spec",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"task",
".",
"Wait",
"(",
"ctx",
")",
"\n",
"}"
] |
// SetBootOptions reconfigures the VirtualMachine with the given options.
|
[
"SetBootOptions",
"reconfigures",
"the",
"VirtualMachine",
"with",
"the",
"given",
"options",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L466-L477
|
21,296
|
vmware/govmomi
|
object/virtual_machine.go
|
Answer
|
func (v VirtualMachine) Answer(ctx context.Context, id, answer string) error {
req := types.AnswerVM{
This: v.Reference(),
QuestionId: id,
AnswerChoice: answer,
}
_, err := methods.AnswerVM(ctx, v.c, &req)
if err != nil {
return err
}
return nil
}
|
go
|
func (v VirtualMachine) Answer(ctx context.Context, id, answer string) error {
req := types.AnswerVM{
This: v.Reference(),
QuestionId: id,
AnswerChoice: answer,
}
_, err := methods.AnswerVM(ctx, v.c, &req)
if err != nil {
return err
}
return nil
}
|
[
"func",
"(",
"v",
"VirtualMachine",
")",
"Answer",
"(",
"ctx",
"context",
".",
"Context",
",",
"id",
",",
"answer",
"string",
")",
"error",
"{",
"req",
":=",
"types",
".",
"AnswerVM",
"{",
"This",
":",
"v",
".",
"Reference",
"(",
")",
",",
"QuestionId",
":",
"id",
",",
"AnswerChoice",
":",
"answer",
",",
"}",
"\n\n",
"_",
",",
"err",
":=",
"methods",
".",
"AnswerVM",
"(",
"ctx",
",",
"v",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Answer answers a pending question.
|
[
"Answer",
"answers",
"a",
"pending",
"question",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L480-L493
|
21,297
|
vmware/govmomi
|
object/virtual_machine.go
|
CreateSnapshot
|
func (v VirtualMachine) CreateSnapshot(ctx context.Context, name string, description string, memory bool, quiesce bool) (*Task, error) {
req := types.CreateSnapshot_Task{
This: v.Reference(),
Name: name,
Description: description,
Memory: memory,
Quiesce: quiesce,
}
res, err := methods.CreateSnapshot_Task(ctx, v.c, &req)
if err != nil {
return nil, err
}
return NewTask(v.c, res.Returnval), nil
}
|
go
|
func (v VirtualMachine) CreateSnapshot(ctx context.Context, name string, description string, memory bool, quiesce bool) (*Task, error) {
req := types.CreateSnapshot_Task{
This: v.Reference(),
Name: name,
Description: description,
Memory: memory,
Quiesce: quiesce,
}
res, err := methods.CreateSnapshot_Task(ctx, v.c, &req)
if err != nil {
return nil, err
}
return NewTask(v.c, res.Returnval), nil
}
|
[
"func",
"(",
"v",
"VirtualMachine",
")",
"CreateSnapshot",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"description",
"string",
",",
"memory",
"bool",
",",
"quiesce",
"bool",
")",
"(",
"*",
"Task",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"CreateSnapshot_Task",
"{",
"This",
":",
"v",
".",
"Reference",
"(",
")",
",",
"Name",
":",
"name",
",",
"Description",
":",
"description",
",",
"Memory",
":",
"memory",
",",
"Quiesce",
":",
"quiesce",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"CreateSnapshot_Task",
"(",
"ctx",
",",
"v",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"NewTask",
"(",
"v",
".",
"c",
",",
"res",
".",
"Returnval",
")",
",",
"nil",
"\n",
"}"
] |
// CreateSnapshot creates a new snapshot of a virtual machine.
|
[
"CreateSnapshot",
"creates",
"a",
"new",
"snapshot",
"of",
"a",
"virtual",
"machine",
"."
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L510-L525
|
21,298
|
vmware/govmomi
|
object/virtual_machine.go
|
RemoveAllSnapshot
|
func (v VirtualMachine) RemoveAllSnapshot(ctx context.Context, consolidate *bool) (*Task, error) {
req := types.RemoveAllSnapshots_Task{
This: v.Reference(),
Consolidate: consolidate,
}
res, err := methods.RemoveAllSnapshots_Task(ctx, v.c, &req)
if err != nil {
return nil, err
}
return NewTask(v.c, res.Returnval), nil
}
|
go
|
func (v VirtualMachine) RemoveAllSnapshot(ctx context.Context, consolidate *bool) (*Task, error) {
req := types.RemoveAllSnapshots_Task{
This: v.Reference(),
Consolidate: consolidate,
}
res, err := methods.RemoveAllSnapshots_Task(ctx, v.c, &req)
if err != nil {
return nil, err
}
return NewTask(v.c, res.Returnval), nil
}
|
[
"func",
"(",
"v",
"VirtualMachine",
")",
"RemoveAllSnapshot",
"(",
"ctx",
"context",
".",
"Context",
",",
"consolidate",
"*",
"bool",
")",
"(",
"*",
"Task",
",",
"error",
")",
"{",
"req",
":=",
"types",
".",
"RemoveAllSnapshots_Task",
"{",
"This",
":",
"v",
".",
"Reference",
"(",
")",
",",
"Consolidate",
":",
"consolidate",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"RemoveAllSnapshots_Task",
"(",
"ctx",
",",
"v",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"NewTask",
"(",
"v",
".",
"c",
",",
"res",
".",
"Returnval",
")",
",",
"nil",
"\n",
"}"
] |
// RemoveAllSnapshot removes all snapshots of a virtual machine
|
[
"RemoveAllSnapshot",
"removes",
"all",
"snapshots",
"of",
"a",
"virtual",
"machine"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L528-L540
|
21,299
|
vmware/govmomi
|
object/virtual_machine.go
|
RemoveSnapshot
|
func (v VirtualMachine) RemoveSnapshot(ctx context.Context, name string, removeChildren bool, consolidate *bool) (*Task, error) {
snapshot, err := v.FindSnapshot(ctx, name)
if err != nil {
return nil, err
}
req := types.RemoveSnapshot_Task{
This: snapshot.Reference(),
RemoveChildren: removeChildren,
Consolidate: consolidate,
}
res, err := methods.RemoveSnapshot_Task(ctx, v.c, &req)
if err != nil {
return nil, err
}
return NewTask(v.c, res.Returnval), nil
}
|
go
|
func (v VirtualMachine) RemoveSnapshot(ctx context.Context, name string, removeChildren bool, consolidate *bool) (*Task, error) {
snapshot, err := v.FindSnapshot(ctx, name)
if err != nil {
return nil, err
}
req := types.RemoveSnapshot_Task{
This: snapshot.Reference(),
RemoveChildren: removeChildren,
Consolidate: consolidate,
}
res, err := methods.RemoveSnapshot_Task(ctx, v.c, &req)
if err != nil {
return nil, err
}
return NewTask(v.c, res.Returnval), nil
}
|
[
"func",
"(",
"v",
"VirtualMachine",
")",
"RemoveSnapshot",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"removeChildren",
"bool",
",",
"consolidate",
"*",
"bool",
")",
"(",
"*",
"Task",
",",
"error",
")",
"{",
"snapshot",
",",
"err",
":=",
"v",
".",
"FindSnapshot",
"(",
"ctx",
",",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"req",
":=",
"types",
".",
"RemoveSnapshot_Task",
"{",
"This",
":",
"snapshot",
".",
"Reference",
"(",
")",
",",
"RemoveChildren",
":",
"removeChildren",
",",
"Consolidate",
":",
"consolidate",
",",
"}",
"\n\n",
"res",
",",
"err",
":=",
"methods",
".",
"RemoveSnapshot_Task",
"(",
"ctx",
",",
"v",
".",
"c",
",",
"&",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"NewTask",
"(",
"v",
".",
"c",
",",
"res",
".",
"Returnval",
")",
",",
"nil",
"\n",
"}"
] |
// RemoveSnapshot removes a named snapshot
|
[
"RemoveSnapshot",
"removes",
"a",
"named",
"snapshot"
] |
fc3f0e9d2275df0e497a80917807a7c72d3c35bc
|
https://github.com/vmware/govmomi/blob/fc3f0e9d2275df0e497a80917807a7c72d3c35bc/object/virtual_machine.go#L594-L612
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.