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
|
---|---|---|---|---|---|---|---|---|---|---|---|
146,000 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewLayer3Forwarding1ClientsByURL
|
func NewLayer3Forwarding1ClientsByURL(loc *url.URL) ([]*Layer3Forwarding1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_Layer3Forwarding_1)
if err != nil {
return nil, err
}
return newLayer3Forwarding1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewLayer3Forwarding1ClientsByURL(loc *url.URL) ([]*Layer3Forwarding1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_Layer3Forwarding_1)
if err != nil {
return nil, err
}
return newLayer3Forwarding1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewLayer3Forwarding1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"Layer3Forwarding1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_Layer3Forwarding_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newLayer3Forwarding1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewLayer3Forwarding1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewLayer3Forwarding1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L1103-L1109
|
146,001 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANCableLinkConfig1Clients
|
func NewWANCableLinkConfig1Clients() (clients []*WANCableLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANCableLinkConfig_1); err != nil {
return
}
clients = newWANCableLinkConfig1ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewWANCableLinkConfig1Clients() (clients []*WANCableLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANCableLinkConfig_1); err != nil {
return
}
clients = newWANCableLinkConfig1ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewWANCableLinkConfig1Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"WANCableLinkConfig1",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_WANCableLinkConfig_1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newWANCableLinkConfig1ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewWANCableLinkConfig1Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewWANCableLinkConfig1Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L1200-L1207
|
146,002 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANCableLinkConfig1ClientsByURL
|
func NewWANCableLinkConfig1ClientsByURL(loc *url.URL) ([]*WANCableLinkConfig1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANCableLinkConfig_1)
if err != nil {
return nil, err
}
return newWANCableLinkConfig1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewWANCableLinkConfig1ClientsByURL(loc *url.URL) ([]*WANCableLinkConfig1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANCableLinkConfig_1)
if err != nil {
return nil, err
}
return newWANCableLinkConfig1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewWANCableLinkConfig1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"WANCableLinkConfig1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_WANCableLinkConfig_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newWANCableLinkConfig1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewWANCableLinkConfig1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewWANCableLinkConfig1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L1215-L1221
|
146,003 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANCommonInterfaceConfig1Clients
|
func NewWANCommonInterfaceConfig1Clients() (clients []*WANCommonInterfaceConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANCommonInterfaceConfig_1); err != nil {
return
}
clients = newWANCommonInterfaceConfig1ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewWANCommonInterfaceConfig1Clients() (clients []*WANCommonInterfaceConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANCommonInterfaceConfig_1); err != nil {
return
}
clients = newWANCommonInterfaceConfig1ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewWANCommonInterfaceConfig1Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"WANCommonInterfaceConfig1",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_WANCommonInterfaceConfig_1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newWANCommonInterfaceConfig1ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewWANCommonInterfaceConfig1Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewWANCommonInterfaceConfig1Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L1538-L1545
|
146,004 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANCommonInterfaceConfig1ClientsByURL
|
func NewWANCommonInterfaceConfig1ClientsByURL(loc *url.URL) ([]*WANCommonInterfaceConfig1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANCommonInterfaceConfig_1)
if err != nil {
return nil, err
}
return newWANCommonInterfaceConfig1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewWANCommonInterfaceConfig1ClientsByURL(loc *url.URL) ([]*WANCommonInterfaceConfig1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANCommonInterfaceConfig_1)
if err != nil {
return nil, err
}
return newWANCommonInterfaceConfig1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewWANCommonInterfaceConfig1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"WANCommonInterfaceConfig1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_WANCommonInterfaceConfig_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newWANCommonInterfaceConfig1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewWANCommonInterfaceConfig1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewWANCommonInterfaceConfig1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L1553-L1559
|
146,005 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANDSLLinkConfig1Clients
|
func NewWANDSLLinkConfig1Clients() (clients []*WANDSLLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANDSLLinkConfig_1); err != nil {
return
}
clients = newWANDSLLinkConfig1ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewWANDSLLinkConfig1Clients() (clients []*WANDSLLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANDSLLinkConfig_1); err != nil {
return
}
clients = newWANDSLLinkConfig1ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewWANDSLLinkConfig1Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"WANDSLLinkConfig1",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_WANDSLLinkConfig_1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newWANDSLLinkConfig1ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewWANDSLLinkConfig1Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewWANDSLLinkConfig1Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L1889-L1896
|
146,006 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANDSLLinkConfig1ClientsByURL
|
func NewWANDSLLinkConfig1ClientsByURL(loc *url.URL) ([]*WANDSLLinkConfig1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANDSLLinkConfig_1)
if err != nil {
return nil, err
}
return newWANDSLLinkConfig1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewWANDSLLinkConfig1ClientsByURL(loc *url.URL) ([]*WANDSLLinkConfig1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANDSLLinkConfig_1)
if err != nil {
return nil, err
}
return newWANDSLLinkConfig1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewWANDSLLinkConfig1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"WANDSLLinkConfig1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_WANDSLLinkConfig_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newWANDSLLinkConfig1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewWANDSLLinkConfig1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewWANDSLLinkConfig1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L1904-L1910
|
146,007 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANEthernetLinkConfig1Clients
|
func NewWANEthernetLinkConfig1Clients() (clients []*WANEthernetLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANEthernetLinkConfig_1); err != nil {
return
}
clients = newWANEthernetLinkConfig1ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewWANEthernetLinkConfig1Clients() (clients []*WANEthernetLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANEthernetLinkConfig_1); err != nil {
return
}
clients = newWANEthernetLinkConfig1ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewWANEthernetLinkConfig1Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"WANEthernetLinkConfig1",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_WANEthernetLinkConfig_1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newWANEthernetLinkConfig1ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewWANEthernetLinkConfig1Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewWANEthernetLinkConfig1Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L2217-L2224
|
146,008 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANEthernetLinkConfig1ClientsByURL
|
func NewWANEthernetLinkConfig1ClientsByURL(loc *url.URL) ([]*WANEthernetLinkConfig1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANEthernetLinkConfig_1)
if err != nil {
return nil, err
}
return newWANEthernetLinkConfig1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewWANEthernetLinkConfig1ClientsByURL(loc *url.URL) ([]*WANEthernetLinkConfig1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANEthernetLinkConfig_1)
if err != nil {
return nil, err
}
return newWANEthernetLinkConfig1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewWANEthernetLinkConfig1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"WANEthernetLinkConfig1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_WANEthernetLinkConfig_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newWANEthernetLinkConfig1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewWANEthernetLinkConfig1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewWANEthernetLinkConfig1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L2232-L2238
|
146,009 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANIPConnection1ClientsByURL
|
func NewWANIPConnection1ClientsByURL(loc *url.URL) ([]*WANIPConnection1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANIPConnection_1)
if err != nil {
return nil, err
}
return newWANIPConnection1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewWANIPConnection1ClientsByURL(loc *url.URL) ([]*WANIPConnection1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANIPConnection_1)
if err != nil {
return nil, err
}
return newWANIPConnection1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewWANIPConnection1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"WANIPConnection1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_WANIPConnection_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newWANIPConnection1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewWANIPConnection1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewWANIPConnection1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L2322-L2328
|
146,010 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANIPConnection2Clients
|
func NewWANIPConnection2Clients() (clients []*WANIPConnection2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANIPConnection_2); err != nil {
return
}
clients = newWANIPConnection2ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewWANIPConnection2Clients() (clients []*WANIPConnection2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANIPConnection_2); err != nil {
return
}
clients = newWANIPConnection2ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewWANIPConnection2Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"WANIPConnection2",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_WANIPConnection_2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newWANIPConnection2ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewWANIPConnection2Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewWANIPConnection2Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L2963-L2970
|
146,011 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANIPConnection2ClientsByURL
|
func NewWANIPConnection2ClientsByURL(loc *url.URL) ([]*WANIPConnection2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANIPConnection_2)
if err != nil {
return nil, err
}
return newWANIPConnection2ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewWANIPConnection2ClientsByURL(loc *url.URL) ([]*WANIPConnection2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANIPConnection_2)
if err != nil {
return nil, err
}
return newWANIPConnection2ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewWANIPConnection2ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"WANIPConnection2",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_WANIPConnection_2",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newWANIPConnection2ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewWANIPConnection2ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewWANIPConnection2ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L2978-L2984
|
146,012 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANIPv6FirewallControl1Clients
|
func NewWANIPv6FirewallControl1Clients() (clients []*WANIPv6FirewallControl1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANIPv6FirewallControl_1); err != nil {
return
}
clients = newWANIPv6FirewallControl1ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewWANIPv6FirewallControl1Clients() (clients []*WANIPv6FirewallControl1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANIPv6FirewallControl_1); err != nil {
return
}
clients = newWANIPv6FirewallControl1ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewWANIPv6FirewallControl1Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"WANIPv6FirewallControl1",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_WANIPv6FirewallControl_1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newWANIPv6FirewallControl1ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewWANIPv6FirewallControl1Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewWANIPv6FirewallControl1Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L3774-L3781
|
146,013 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANIPv6FirewallControl1ClientsByURL
|
func NewWANIPv6FirewallControl1ClientsByURL(loc *url.URL) ([]*WANIPv6FirewallControl1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANIPv6FirewallControl_1)
if err != nil {
return nil, err
}
return newWANIPv6FirewallControl1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewWANIPv6FirewallControl1ClientsByURL(loc *url.URL) ([]*WANIPv6FirewallControl1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANIPv6FirewallControl_1)
if err != nil {
return nil, err
}
return newWANIPv6FirewallControl1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewWANIPv6FirewallControl1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"WANIPv6FirewallControl1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_WANIPv6FirewallControl_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newWANIPv6FirewallControl1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewWANIPv6FirewallControl1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewWANIPv6FirewallControl1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L3789-L3795
|
146,014 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANPOTSLinkConfig1Clients
|
func NewWANPOTSLinkConfig1Clients() (clients []*WANPOTSLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANPOTSLinkConfig_1); err != nil {
return
}
clients = newWANPOTSLinkConfig1ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewWANPOTSLinkConfig1Clients() (clients []*WANPOTSLinkConfig1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_WANPOTSLinkConfig_1); err != nil {
return
}
clients = newWANPOTSLinkConfig1ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewWANPOTSLinkConfig1Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"WANPOTSLinkConfig1",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_WANPOTSLinkConfig_1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newWANPOTSLinkConfig1ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewWANPOTSLinkConfig1Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewWANPOTSLinkConfig1Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L4090-L4097
|
146,015 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANPOTSLinkConfig1ClientsByURL
|
func NewWANPOTSLinkConfig1ClientsByURL(loc *url.URL) ([]*WANPOTSLinkConfig1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANPOTSLinkConfig_1)
if err != nil {
return nil, err
}
return newWANPOTSLinkConfig1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewWANPOTSLinkConfig1ClientsByURL(loc *url.URL) ([]*WANPOTSLinkConfig1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANPOTSLinkConfig_1)
if err != nil {
return nil, err
}
return newWANPOTSLinkConfig1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewWANPOTSLinkConfig1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"WANPOTSLinkConfig1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_WANPOTSLinkConfig_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newWANPOTSLinkConfig1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewWANPOTSLinkConfig1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewWANPOTSLinkConfig1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L4105-L4111
|
146,016 |
huin/goupnp
|
dcps/internetgateway2/internetgateway2.go
|
NewWANPPPConnection1ClientsByURL
|
func NewWANPPPConnection1ClientsByURL(loc *url.URL) ([]*WANPPPConnection1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANPPPConnection_1)
if err != nil {
return nil, err
}
return newWANPPPConnection1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewWANPPPConnection1ClientsByURL(loc *url.URL) ([]*WANPPPConnection1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_WANPPPConnection_1)
if err != nil {
return nil, err
}
return newWANPPPConnection1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewWANPPPConnection1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"WANPPPConnection1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_WANPPPConnection_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newWANPPPConnection1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewWANPPPConnection1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewWANPPPConnection1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/internetgateway2/internetgateway2.go#L4432-L4438
|
146,017 |
huin/goupnp
|
cmd/goupnpdcpgen/dcp.go
|
extractURNParts
|
func extractURNParts(urn, expectedPrefix string) (*URNParts, error) {
if !strings.HasPrefix(urn, expectedPrefix) {
return nil, fmt.Errorf("%q does not have expected prefix %q", urn, expectedPrefix)
}
parts := strings.SplitN(strings.TrimPrefix(urn, expectedPrefix), ":", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("%q does not have a name and version", urn)
}
name, version := parts[0], parts[1]
return &URNParts{urn, name, version}, nil
}
|
go
|
func extractURNParts(urn, expectedPrefix string) (*URNParts, error) {
if !strings.HasPrefix(urn, expectedPrefix) {
return nil, fmt.Errorf("%q does not have expected prefix %q", urn, expectedPrefix)
}
parts := strings.SplitN(strings.TrimPrefix(urn, expectedPrefix), ":", 2)
if len(parts) != 2 {
return nil, fmt.Errorf("%q does not have a name and version", urn)
}
name, version := parts[0], parts[1]
return &URNParts{urn, name, version}, nil
}
|
[
"func",
"extractURNParts",
"(",
"urn",
",",
"expectedPrefix",
"string",
")",
"(",
"*",
"URNParts",
",",
"error",
")",
"{",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"urn",
",",
"expectedPrefix",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"urn",
",",
"expectedPrefix",
")",
"\n",
"}",
"\n",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"strings",
".",
"TrimPrefix",
"(",
"urn",
",",
"expectedPrefix",
")",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"!=",
"2",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"urn",
")",
"\n",
"}",
"\n",
"name",
",",
"version",
":=",
"parts",
"[",
"0",
"]",
",",
"parts",
"[",
"1",
"]",
"\n",
"return",
"&",
"URNParts",
"{",
"urn",
",",
"name",
",",
"version",
"}",
",",
"nil",
"\n",
"}"
] |
// extractURNParts extracts the name and version from a URN string.
|
[
"extractURNParts",
"extracts",
"the",
"name",
"and",
"version",
"from",
"a",
"URN",
"string",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/cmd/goupnpdcpgen/dcp.go#L212-L222
|
146,018 |
huin/goupnp
|
httpu/serve.go
|
Serve
|
func (srv *Server) Serve(l net.PacketConn) error {
maxMessageBytes := DefaultMaxMessageBytes
if srv.MaxMessageBytes != 0 {
maxMessageBytes = srv.MaxMessageBytes
}
for {
buf := make([]byte, maxMessageBytes)
n, peerAddr, err := l.ReadFrom(buf)
if err != nil {
return err
}
buf = buf[:n]
go func(buf []byte, peerAddr net.Addr) {
// At least one router's UPnP implementation has added a trailing space
// after "HTTP/1.1" - trim it.
buf = trailingWhitespaceRx.ReplaceAllLiteral(buf, crlf)
req, err := http.ReadRequest(bufio.NewReader(bytes.NewBuffer(buf)))
if err != nil {
log.Printf("httpu: Failed to parse request: %v", err)
return
}
req.RemoteAddr = peerAddr.String()
srv.Handler.ServeMessage(req)
// No need to call req.Body.Close - underlying reader is bytes.Buffer.
}(buf, peerAddr)
}
}
|
go
|
func (srv *Server) Serve(l net.PacketConn) error {
maxMessageBytes := DefaultMaxMessageBytes
if srv.MaxMessageBytes != 0 {
maxMessageBytes = srv.MaxMessageBytes
}
for {
buf := make([]byte, maxMessageBytes)
n, peerAddr, err := l.ReadFrom(buf)
if err != nil {
return err
}
buf = buf[:n]
go func(buf []byte, peerAddr net.Addr) {
// At least one router's UPnP implementation has added a trailing space
// after "HTTP/1.1" - trim it.
buf = trailingWhitespaceRx.ReplaceAllLiteral(buf, crlf)
req, err := http.ReadRequest(bufio.NewReader(bytes.NewBuffer(buf)))
if err != nil {
log.Printf("httpu: Failed to parse request: %v", err)
return
}
req.RemoteAddr = peerAddr.String()
srv.Handler.ServeMessage(req)
// No need to call req.Body.Close - underlying reader is bytes.Buffer.
}(buf, peerAddr)
}
}
|
[
"func",
"(",
"srv",
"*",
"Server",
")",
"Serve",
"(",
"l",
"net",
".",
"PacketConn",
")",
"error",
"{",
"maxMessageBytes",
":=",
"DefaultMaxMessageBytes",
"\n",
"if",
"srv",
".",
"MaxMessageBytes",
"!=",
"0",
"{",
"maxMessageBytes",
"=",
"srv",
".",
"MaxMessageBytes",
"\n",
"}",
"\n",
"for",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"maxMessageBytes",
")",
"\n",
"n",
",",
"peerAddr",
",",
"err",
":=",
"l",
".",
"ReadFrom",
"(",
"buf",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"buf",
"=",
"buf",
"[",
":",
"n",
"]",
"\n\n",
"go",
"func",
"(",
"buf",
"[",
"]",
"byte",
",",
"peerAddr",
"net",
".",
"Addr",
")",
"{",
"// At least one router's UPnP implementation has added a trailing space",
"// after \"HTTP/1.1\" - trim it.",
"buf",
"=",
"trailingWhitespaceRx",
".",
"ReplaceAllLiteral",
"(",
"buf",
",",
"crlf",
")",
"\n\n",
"req",
",",
"err",
":=",
"http",
".",
"ReadRequest",
"(",
"bufio",
".",
"NewReader",
"(",
"bytes",
".",
"NewBuffer",
"(",
"buf",
")",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"req",
".",
"RemoteAddr",
"=",
"peerAddr",
".",
"String",
"(",
")",
"\n",
"srv",
".",
"Handler",
".",
"ServeMessage",
"(",
"req",
")",
"\n",
"// No need to call req.Body.Close - underlying reader is bytes.Buffer.",
"}",
"(",
"buf",
",",
"peerAddr",
")",
"\n",
"}",
"\n",
"}"
] |
// Serve messages received on the given packet listener to the srv.Handler.
|
[
"Serve",
"messages",
"received",
"on",
"the",
"given",
"packet",
"listener",
"to",
"the",
"srv",
".",
"Handler",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/httpu/serve.go#L71-L99
|
146,019 |
huin/goupnp
|
httpu/serve.go
|
Serve
|
func Serve(l net.PacketConn, handler Handler) error {
srv := Server{
Handler: handler,
MaxMessageBytes: DefaultMaxMessageBytes,
}
return srv.Serve(l)
}
|
go
|
func Serve(l net.PacketConn, handler Handler) error {
srv := Server{
Handler: handler,
MaxMessageBytes: DefaultMaxMessageBytes,
}
return srv.Serve(l)
}
|
[
"func",
"Serve",
"(",
"l",
"net",
".",
"PacketConn",
",",
"handler",
"Handler",
")",
"error",
"{",
"srv",
":=",
"Server",
"{",
"Handler",
":",
"handler",
",",
"MaxMessageBytes",
":",
"DefaultMaxMessageBytes",
",",
"}",
"\n",
"return",
"srv",
".",
"Serve",
"(",
"l",
")",
"\n",
"}"
] |
// Serve messages received on the given packet listener to the given handler.
|
[
"Serve",
"messages",
"received",
"on",
"the",
"given",
"packet",
"listener",
"to",
"the",
"given",
"handler",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/httpu/serve.go#L102-L108
|
146,020 |
huin/goupnp
|
dcps/av1/av1.go
|
NewAVTransport1Clients
|
func NewAVTransport1Clients() (clients []*AVTransport1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_AVTransport_1); err != nil {
return
}
clients = newAVTransport1ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewAVTransport1Clients() (clients []*AVTransport1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_AVTransport_1); err != nil {
return
}
clients = newAVTransport1ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewAVTransport1Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"AVTransport1",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_AVTransport_1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newAVTransport1ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewAVTransport1Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewAVTransport1Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L54-L61
|
146,021 |
huin/goupnp
|
dcps/av1/av1.go
|
NewAVTransport1ClientsByURL
|
func NewAVTransport1ClientsByURL(loc *url.URL) ([]*AVTransport1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_AVTransport_1)
if err != nil {
return nil, err
}
return newAVTransport1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewAVTransport1ClientsByURL(loc *url.URL) ([]*AVTransport1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_AVTransport_1)
if err != nil {
return nil, err
}
return newAVTransport1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewAVTransport1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"AVTransport1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_AVTransport_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newAVTransport1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewAVTransport1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewAVTransport1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L69-L75
|
146,022 |
huin/goupnp
|
dcps/av1/av1.go
|
NewAVTransport2Clients
|
func NewAVTransport2Clients() (clients []*AVTransport2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_AVTransport_2); err != nil {
return
}
clients = newAVTransport2ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewAVTransport2Clients() (clients []*AVTransport2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_AVTransport_2); err != nil {
return
}
clients = newAVTransport2ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewAVTransport2Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"AVTransport2",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_AVTransport_2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newAVTransport2ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewAVTransport2Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewAVTransport2Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L737-L744
|
146,023 |
huin/goupnp
|
dcps/av1/av1.go
|
NewAVTransport2ClientsByURL
|
func NewAVTransport2ClientsByURL(loc *url.URL) ([]*AVTransport2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_AVTransport_2)
if err != nil {
return nil, err
}
return newAVTransport2ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewAVTransport2ClientsByURL(loc *url.URL) ([]*AVTransport2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_AVTransport_2)
if err != nil {
return nil, err
}
return newAVTransport2ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewAVTransport2ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"AVTransport2",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_AVTransport_2",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newAVTransport2ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewAVTransport2ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewAVTransport2ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L752-L758
|
146,024 |
huin/goupnp
|
dcps/av1/av1.go
|
NewConnectionManager1Clients
|
func NewConnectionManager1Clients() (clients []*ConnectionManager1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ConnectionManager_1); err != nil {
return
}
clients = newConnectionManager1ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewConnectionManager1Clients() (clients []*ConnectionManager1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ConnectionManager_1); err != nil {
return
}
clients = newConnectionManager1ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewConnectionManager1Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"ConnectionManager1",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_ConnectionManager_1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newConnectionManager1ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewConnectionManager1Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewConnectionManager1Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L1610-L1617
|
146,025 |
huin/goupnp
|
dcps/av1/av1.go
|
NewConnectionManager1ClientsByURL
|
func NewConnectionManager1ClientsByURL(loc *url.URL) ([]*ConnectionManager1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ConnectionManager_1)
if err != nil {
return nil, err
}
return newConnectionManager1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewConnectionManager1ClientsByURL(loc *url.URL) ([]*ConnectionManager1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ConnectionManager_1)
if err != nil {
return nil, err
}
return newConnectionManager1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewConnectionManager1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"ConnectionManager1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_ConnectionManager_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newConnectionManager1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewConnectionManager1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewConnectionManager1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L1625-L1631
|
146,026 |
huin/goupnp
|
dcps/av1/av1.go
|
NewConnectionManager2Clients
|
func NewConnectionManager2Clients() (clients []*ConnectionManager2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ConnectionManager_2); err != nil {
return
}
clients = newConnectionManager2ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewConnectionManager2Clients() (clients []*ConnectionManager2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ConnectionManager_2); err != nil {
return
}
clients = newConnectionManager2ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewConnectionManager2Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"ConnectionManager2",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_ConnectionManager_2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newConnectionManager2ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewConnectionManager2Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewConnectionManager2Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L1869-L1876
|
146,027 |
huin/goupnp
|
dcps/av1/av1.go
|
NewConnectionManager2ClientsByURL
|
func NewConnectionManager2ClientsByURL(loc *url.URL) ([]*ConnectionManager2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ConnectionManager_2)
if err != nil {
return nil, err
}
return newConnectionManager2ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewConnectionManager2ClientsByURL(loc *url.URL) ([]*ConnectionManager2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ConnectionManager_2)
if err != nil {
return nil, err
}
return newConnectionManager2ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewConnectionManager2ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"ConnectionManager2",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_ConnectionManager_2",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newConnectionManager2ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewConnectionManager2ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewConnectionManager2ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L1884-L1890
|
146,028 |
huin/goupnp
|
dcps/av1/av1.go
|
NewContentDirectory1Clients
|
func NewContentDirectory1Clients() (clients []*ContentDirectory1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ContentDirectory_1); err != nil {
return
}
clients = newContentDirectory1ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewContentDirectory1Clients() (clients []*ContentDirectory1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ContentDirectory_1); err != nil {
return
}
clients = newContentDirectory1ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewContentDirectory1Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"ContentDirectory1",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_ContentDirectory_1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newContentDirectory1ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewContentDirectory1Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewContentDirectory1Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L2128-L2135
|
146,029 |
huin/goupnp
|
dcps/av1/av1.go
|
NewContentDirectory1ClientsByURL
|
func NewContentDirectory1ClientsByURL(loc *url.URL) ([]*ContentDirectory1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ContentDirectory_1)
if err != nil {
return nil, err
}
return newContentDirectory1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewContentDirectory1ClientsByURL(loc *url.URL) ([]*ContentDirectory1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ContentDirectory_1)
if err != nil {
return nil, err
}
return newContentDirectory1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewContentDirectory1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"ContentDirectory1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_ContentDirectory_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newContentDirectory1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewContentDirectory1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewContentDirectory1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L2143-L2149
|
146,030 |
huin/goupnp
|
dcps/av1/av1.go
|
NewContentDirectory2Clients
|
func NewContentDirectory2Clients() (clients []*ContentDirectory2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ContentDirectory_2); err != nil {
return
}
clients = newContentDirectory2ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewContentDirectory2Clients() (clients []*ContentDirectory2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ContentDirectory_2); err != nil {
return
}
clients = newContentDirectory2ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewContentDirectory2Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"ContentDirectory2",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_ContentDirectory_2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newContentDirectory2ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewContentDirectory2Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewContentDirectory2Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L2696-L2703
|
146,031 |
huin/goupnp
|
dcps/av1/av1.go
|
NewContentDirectory2ClientsByURL
|
func NewContentDirectory2ClientsByURL(loc *url.URL) ([]*ContentDirectory2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ContentDirectory_2)
if err != nil {
return nil, err
}
return newContentDirectory2ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewContentDirectory2ClientsByURL(loc *url.URL) ([]*ContentDirectory2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ContentDirectory_2)
if err != nil {
return nil, err
}
return newContentDirectory2ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewContentDirectory2ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"ContentDirectory2",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_ContentDirectory_2",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newContentDirectory2ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewContentDirectory2ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewContentDirectory2ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L2711-L2717
|
146,032 |
huin/goupnp
|
dcps/av1/av1.go
|
NewContentDirectory3Clients
|
func NewContentDirectory3Clients() (clients []*ContentDirectory3, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ContentDirectory_3); err != nil {
return
}
clients = newContentDirectory3ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewContentDirectory3Clients() (clients []*ContentDirectory3, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ContentDirectory_3); err != nil {
return
}
clients = newContentDirectory3ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewContentDirectory3Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"ContentDirectory3",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_ContentDirectory_3",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newContentDirectory3ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewContentDirectory3Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewContentDirectory3Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L3351-L3358
|
146,033 |
huin/goupnp
|
dcps/av1/av1.go
|
NewContentDirectory3ClientsByURL
|
func NewContentDirectory3ClientsByURL(loc *url.URL) ([]*ContentDirectory3, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ContentDirectory_3)
if err != nil {
return nil, err
}
return newContentDirectory3ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewContentDirectory3ClientsByURL(loc *url.URL) ([]*ContentDirectory3, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ContentDirectory_3)
if err != nil {
return nil, err
}
return newContentDirectory3ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewContentDirectory3ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"ContentDirectory3",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_ContentDirectory_3",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newContentDirectory3ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewContentDirectory3ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewContentDirectory3ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L3366-L3372
|
146,034 |
huin/goupnp
|
dcps/av1/av1.go
|
NewRenderingControl1Clients
|
func NewRenderingControl1Clients() (clients []*RenderingControl1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_RenderingControl_1); err != nil {
return
}
clients = newRenderingControl1ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewRenderingControl1Clients() (clients []*RenderingControl1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_RenderingControl_1); err != nil {
return
}
clients = newRenderingControl1ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewRenderingControl1Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"RenderingControl1",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_RenderingControl_1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newRenderingControl1ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewRenderingControl1Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewRenderingControl1Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L4101-L4108
|
146,035 |
huin/goupnp
|
dcps/av1/av1.go
|
NewRenderingControl1ClientsByURL
|
func NewRenderingControl1ClientsByURL(loc *url.URL) ([]*RenderingControl1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_RenderingControl_1)
if err != nil {
return nil, err
}
return newRenderingControl1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewRenderingControl1ClientsByURL(loc *url.URL) ([]*RenderingControl1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_RenderingControl_1)
if err != nil {
return nil, err
}
return newRenderingControl1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewRenderingControl1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"RenderingControl1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_RenderingControl_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newRenderingControl1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewRenderingControl1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewRenderingControl1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L4116-L4122
|
146,036 |
huin/goupnp
|
dcps/av1/av1.go
|
NewRenderingControl2Clients
|
func NewRenderingControl2Clients() (clients []*RenderingControl2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_RenderingControl_2); err != nil {
return
}
clients = newRenderingControl2ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewRenderingControl2Clients() (clients []*RenderingControl2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_RenderingControl_2); err != nil {
return
}
clients = newRenderingControl2ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewRenderingControl2Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"RenderingControl2",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_RenderingControl_2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newRenderingControl2ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewRenderingControl2Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewRenderingControl2Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L5424-L5431
|
146,037 |
huin/goupnp
|
dcps/av1/av1.go
|
NewRenderingControl2ClientsByURL
|
func NewRenderingControl2ClientsByURL(loc *url.URL) ([]*RenderingControl2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_RenderingControl_2)
if err != nil {
return nil, err
}
return newRenderingControl2ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewRenderingControl2ClientsByURL(loc *url.URL) ([]*RenderingControl2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_RenderingControl_2)
if err != nil {
return nil, err
}
return newRenderingControl2ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewRenderingControl2ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"RenderingControl2",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_RenderingControl_2",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newRenderingControl2ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewRenderingControl2ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewRenderingControl2ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L5439-L5445
|
146,038 |
huin/goupnp
|
dcps/av1/av1.go
|
NewScheduledRecording1Clients
|
func NewScheduledRecording1Clients() (clients []*ScheduledRecording1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ScheduledRecording_1); err != nil {
return
}
clients = newScheduledRecording1ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewScheduledRecording1Clients() (clients []*ScheduledRecording1, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ScheduledRecording_1); err != nil {
return
}
clients = newScheduledRecording1ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewScheduledRecording1Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"ScheduledRecording1",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_ScheduledRecording_1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newScheduledRecording1ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewScheduledRecording1Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewScheduledRecording1Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L6838-L6845
|
146,039 |
huin/goupnp
|
dcps/av1/av1.go
|
NewScheduledRecording1ClientsByURL
|
func NewScheduledRecording1ClientsByURL(loc *url.URL) ([]*ScheduledRecording1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ScheduledRecording_1)
if err != nil {
return nil, err
}
return newScheduledRecording1ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewScheduledRecording1ClientsByURL(loc *url.URL) ([]*ScheduledRecording1, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ScheduledRecording_1)
if err != nil {
return nil, err
}
return newScheduledRecording1ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewScheduledRecording1ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"ScheduledRecording1",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_ScheduledRecording_1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newScheduledRecording1ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewScheduledRecording1ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewScheduledRecording1ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L6853-L6859
|
146,040 |
huin/goupnp
|
dcps/av1/av1.go
|
NewScheduledRecording2Clients
|
func NewScheduledRecording2Clients() (clients []*ScheduledRecording2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ScheduledRecording_2); err != nil {
return
}
clients = newScheduledRecording2ClientsFromGenericClients(genericClients)
return
}
|
go
|
func NewScheduledRecording2Clients() (clients []*ScheduledRecording2, errors []error, err error) {
var genericClients []goupnp.ServiceClient
if genericClients, errors, err = goupnp.NewServiceClients(URN_ScheduledRecording_2); err != nil {
return
}
clients = newScheduledRecording2ClientsFromGenericClients(genericClients)
return
}
|
[
"func",
"NewScheduledRecording2Clients",
"(",
")",
"(",
"clients",
"[",
"]",
"*",
"ScheduledRecording2",
",",
"errors",
"[",
"]",
"error",
",",
"err",
"error",
")",
"{",
"var",
"genericClients",
"[",
"]",
"goupnp",
".",
"ServiceClient",
"\n",
"if",
"genericClients",
",",
"errors",
",",
"err",
"=",
"goupnp",
".",
"NewServiceClients",
"(",
"URN_ScheduledRecording_2",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"clients",
"=",
"newScheduledRecording2ClientsFromGenericClients",
"(",
"genericClients",
")",
"\n",
"return",
"\n",
"}"
] |
// NewScheduledRecording2Clients discovers instances of the service on the network,
// and returns clients to any that are found. errors will contain an error for
// any devices that replied but which could not be queried, and err will be set
// if the discovery process failed outright.
//
// This is a typical entry calling point into this package.
|
[
"NewScheduledRecording2Clients",
"discovers",
"instances",
"of",
"the",
"service",
"on",
"the",
"network",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"errors",
"will",
"contain",
"an",
"error",
"for",
"any",
"devices",
"that",
"replied",
"but",
"which",
"could",
"not",
"be",
"queried",
"and",
"err",
"will",
"be",
"set",
"if",
"the",
"discovery",
"process",
"failed",
"outright",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L7513-L7520
|
146,041 |
huin/goupnp
|
dcps/av1/av1.go
|
NewScheduledRecording2ClientsByURL
|
func NewScheduledRecording2ClientsByURL(loc *url.URL) ([]*ScheduledRecording2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ScheduledRecording_2)
if err != nil {
return nil, err
}
return newScheduledRecording2ClientsFromGenericClients(genericClients), nil
}
|
go
|
func NewScheduledRecording2ClientsByURL(loc *url.URL) ([]*ScheduledRecording2, error) {
genericClients, err := goupnp.NewServiceClientsByURL(loc, URN_ScheduledRecording_2)
if err != nil {
return nil, err
}
return newScheduledRecording2ClientsFromGenericClients(genericClients), nil
}
|
[
"func",
"NewScheduledRecording2ClientsByURL",
"(",
"loc",
"*",
"url",
".",
"URL",
")",
"(",
"[",
"]",
"*",
"ScheduledRecording2",
",",
"error",
")",
"{",
"genericClients",
",",
"err",
":=",
"goupnp",
".",
"NewServiceClientsByURL",
"(",
"loc",
",",
"URN_ScheduledRecording_2",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"newScheduledRecording2ClientsFromGenericClients",
"(",
"genericClients",
")",
",",
"nil",
"\n",
"}"
] |
// NewScheduledRecording2ClientsByURL discovers instances of the service at the given
// URL, and returns clients to any that are found. An error is returned if
// there was an error probing the service.
//
// This is a typical entry calling point into this package when reusing an
// previously discovered service URL.
|
[
"NewScheduledRecording2ClientsByURL",
"discovers",
"instances",
"of",
"the",
"service",
"at",
"the",
"given",
"URL",
"and",
"returns",
"clients",
"to",
"any",
"that",
"are",
"found",
".",
"An",
"error",
"is",
"returned",
"if",
"there",
"was",
"an",
"error",
"probing",
"the",
"service",
".",
"This",
"is",
"a",
"typical",
"entry",
"calling",
"point",
"into",
"this",
"package",
"when",
"reusing",
"an",
"previously",
"discovered",
"service",
"URL",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/dcps/av1/av1.go#L7528-L7534
|
146,042 |
huin/goupnp
|
ssdp/registry.go
|
NewServerAndRegistry
|
func NewServerAndRegistry() (*httpu.Server, *Registry) {
reg := NewRegistry()
srv := &httpu.Server{
Addr: ssdpUDP4Addr,
Multicast: true,
Handler: reg,
}
return srv, reg
}
|
go
|
func NewServerAndRegistry() (*httpu.Server, *Registry) {
reg := NewRegistry()
srv := &httpu.Server{
Addr: ssdpUDP4Addr,
Multicast: true,
Handler: reg,
}
return srv, reg
}
|
[
"func",
"NewServerAndRegistry",
"(",
")",
"(",
"*",
"httpu",
".",
"Server",
",",
"*",
"Registry",
")",
"{",
"reg",
":=",
"NewRegistry",
"(",
")",
"\n",
"srv",
":=",
"&",
"httpu",
".",
"Server",
"{",
"Addr",
":",
"ssdpUDP4Addr",
",",
"Multicast",
":",
"true",
",",
"Handler",
":",
"reg",
",",
"}",
"\n",
"return",
"srv",
",",
"reg",
"\n",
"}"
] |
// NewServerAndRegistry is a convenience function to create a registry, and an
// httpu server to pass it messages. Call ListenAndServe on the server for
// messages to be processed.
|
[
"NewServerAndRegistry",
"is",
"a",
"convenience",
"function",
"to",
"create",
"a",
"registry",
"and",
"an",
"httpu",
"server",
"to",
"pass",
"it",
"messages",
".",
"Call",
"ListenAndServe",
"on",
"the",
"server",
"for",
"messages",
"to",
"be",
"processed",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/ssdp/registry.go#L183-L191
|
146,043 |
huin/goupnp
|
device.go
|
SetURLBase
|
func (root *RootDevice) SetURLBase(urlBase *url.URL) {
root.URLBase = *urlBase
root.URLBaseStr = urlBase.String()
root.Device.SetURLBase(urlBase)
}
|
go
|
func (root *RootDevice) SetURLBase(urlBase *url.URL) {
root.URLBase = *urlBase
root.URLBaseStr = urlBase.String()
root.Device.SetURLBase(urlBase)
}
|
[
"func",
"(",
"root",
"*",
"RootDevice",
")",
"SetURLBase",
"(",
"urlBase",
"*",
"url",
".",
"URL",
")",
"{",
"root",
".",
"URLBase",
"=",
"*",
"urlBase",
"\n",
"root",
".",
"URLBaseStr",
"=",
"urlBase",
".",
"String",
"(",
")",
"\n",
"root",
".",
"Device",
".",
"SetURLBase",
"(",
"urlBase",
")",
"\n",
"}"
] |
// SetURLBase sets the URLBase for the RootDevice and its underlying components.
|
[
"SetURLBase",
"sets",
"the",
"URLBase",
"for",
"the",
"RootDevice",
"and",
"its",
"underlying",
"components",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/device.go#L31-L35
|
146,044 |
huin/goupnp
|
device.go
|
VisitDevices
|
func (device *Device) VisitDevices(visitor func(*Device)) {
visitor(device)
for i := range device.Devices {
device.Devices[i].VisitDevices(visitor)
}
}
|
go
|
func (device *Device) VisitDevices(visitor func(*Device)) {
visitor(device)
for i := range device.Devices {
device.Devices[i].VisitDevices(visitor)
}
}
|
[
"func",
"(",
"device",
"*",
"Device",
")",
"VisitDevices",
"(",
"visitor",
"func",
"(",
"*",
"Device",
")",
")",
"{",
"visitor",
"(",
"device",
")",
"\n",
"for",
"i",
":=",
"range",
"device",
".",
"Devices",
"{",
"device",
".",
"Devices",
"[",
"i",
"]",
".",
"VisitDevices",
"(",
"visitor",
")",
"\n",
"}",
"\n",
"}"
] |
// VisitDevices calls visitor for the device, and all its descendent devices.
|
[
"VisitDevices",
"calls",
"visitor",
"for",
"the",
"device",
"and",
"all",
"its",
"descendent",
"devices",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/device.go#L66-L71
|
146,045 |
huin/goupnp
|
device.go
|
VisitServices
|
func (device *Device) VisitServices(visitor func(*Service)) {
device.VisitDevices(func(d *Device) {
for i := range d.Services {
visitor(&d.Services[i])
}
})
}
|
go
|
func (device *Device) VisitServices(visitor func(*Service)) {
device.VisitDevices(func(d *Device) {
for i := range d.Services {
visitor(&d.Services[i])
}
})
}
|
[
"func",
"(",
"device",
"*",
"Device",
")",
"VisitServices",
"(",
"visitor",
"func",
"(",
"*",
"Service",
")",
")",
"{",
"device",
".",
"VisitDevices",
"(",
"func",
"(",
"d",
"*",
"Device",
")",
"{",
"for",
"i",
":=",
"range",
"d",
".",
"Services",
"{",
"visitor",
"(",
"&",
"d",
".",
"Services",
"[",
"i",
"]",
")",
"\n",
"}",
"\n",
"}",
")",
"\n",
"}"
] |
// VisitServices calls visitor for all Services under the device and all its
// descendent devices.
|
[
"VisitServices",
"calls",
"visitor",
"for",
"all",
"Services",
"under",
"the",
"device",
"and",
"all",
"its",
"descendent",
"devices",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/device.go#L75-L81
|
146,046 |
huin/goupnp
|
device.go
|
SetURLBase
|
func (device *Device) SetURLBase(urlBase *url.URL) {
device.ManufacturerURL.SetURLBase(urlBase)
device.ModelURL.SetURLBase(urlBase)
device.PresentationURL.SetURLBase(urlBase)
for i := range device.Icons {
device.Icons[i].SetURLBase(urlBase)
}
for i := range device.Services {
device.Services[i].SetURLBase(urlBase)
}
for i := range device.Devices {
device.Devices[i].SetURLBase(urlBase)
}
}
|
go
|
func (device *Device) SetURLBase(urlBase *url.URL) {
device.ManufacturerURL.SetURLBase(urlBase)
device.ModelURL.SetURLBase(urlBase)
device.PresentationURL.SetURLBase(urlBase)
for i := range device.Icons {
device.Icons[i].SetURLBase(urlBase)
}
for i := range device.Services {
device.Services[i].SetURLBase(urlBase)
}
for i := range device.Devices {
device.Devices[i].SetURLBase(urlBase)
}
}
|
[
"func",
"(",
"device",
"*",
"Device",
")",
"SetURLBase",
"(",
"urlBase",
"*",
"url",
".",
"URL",
")",
"{",
"device",
".",
"ManufacturerURL",
".",
"SetURLBase",
"(",
"urlBase",
")",
"\n",
"device",
".",
"ModelURL",
".",
"SetURLBase",
"(",
"urlBase",
")",
"\n",
"device",
".",
"PresentationURL",
".",
"SetURLBase",
"(",
"urlBase",
")",
"\n",
"for",
"i",
":=",
"range",
"device",
".",
"Icons",
"{",
"device",
".",
"Icons",
"[",
"i",
"]",
".",
"SetURLBase",
"(",
"urlBase",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"device",
".",
"Services",
"{",
"device",
".",
"Services",
"[",
"i",
"]",
".",
"SetURLBase",
"(",
"urlBase",
")",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"device",
".",
"Devices",
"{",
"device",
".",
"Devices",
"[",
"i",
"]",
".",
"SetURLBase",
"(",
"urlBase",
")",
"\n",
"}",
"\n",
"}"
] |
// SetURLBase sets the URLBase for the Device and its underlying components.
|
[
"SetURLBase",
"sets",
"the",
"URLBase",
"for",
"the",
"Device",
"and",
"its",
"underlying",
"components",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/device.go#L96-L109
|
146,047 |
huin/goupnp
|
device.go
|
SetURLBase
|
func (icon *Icon) SetURLBase(url *url.URL) {
icon.URL.SetURLBase(url)
}
|
go
|
func (icon *Icon) SetURLBase(url *url.URL) {
icon.URL.SetURLBase(url)
}
|
[
"func",
"(",
"icon",
"*",
"Icon",
")",
"SetURLBase",
"(",
"url",
"*",
"url",
".",
"URL",
")",
"{",
"icon",
".",
"URL",
".",
"SetURLBase",
"(",
"url",
")",
"\n",
"}"
] |
// SetURLBase sets the URLBase for the Icon.
|
[
"SetURLBase",
"sets",
"the",
"URLBase",
"for",
"the",
"Icon",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/device.go#L126-L128
|
146,048 |
huin/goupnp
|
device.go
|
SetURLBase
|
func (srv *Service) SetURLBase(urlBase *url.URL) {
srv.SCPDURL.SetURLBase(urlBase)
srv.ControlURL.SetURLBase(urlBase)
srv.EventSubURL.SetURLBase(urlBase)
}
|
go
|
func (srv *Service) SetURLBase(urlBase *url.URL) {
srv.SCPDURL.SetURLBase(urlBase)
srv.ControlURL.SetURLBase(urlBase)
srv.EventSubURL.SetURLBase(urlBase)
}
|
[
"func",
"(",
"srv",
"*",
"Service",
")",
"SetURLBase",
"(",
"urlBase",
"*",
"url",
".",
"URL",
")",
"{",
"srv",
".",
"SCPDURL",
".",
"SetURLBase",
"(",
"urlBase",
")",
"\n",
"srv",
".",
"ControlURL",
".",
"SetURLBase",
"(",
"urlBase",
")",
"\n",
"srv",
".",
"EventSubURL",
".",
"SetURLBase",
"(",
"urlBase",
")",
"\n",
"}"
] |
// SetURLBase sets the URLBase for the Service.
|
[
"SetURLBase",
"sets",
"the",
"URLBase",
"for",
"the",
"Service",
"."
] |
656e61dfadd241c7cbdd22a023fa81ecb6860ea8
|
https://github.com/huin/goupnp/blob/656e61dfadd241c7cbdd22a023fa81ecb6860ea8/device.go#L140-L144
|
146,049 |
apcera/libretto
|
virtualmachine/vsphere/util.go
|
GetDatacenter
|
func GetDatacenter(vm *VM) (*mo.Datacenter, error) {
dcList, err := vm.finder.DatacenterList(vm.ctx, "*")
if err != nil {
return nil, NewErrorObjectNotFound(err, vm.Datacenter)
}
for _, dc := range dcList {
dcMo := mo.Datacenter{}
ps := []string{"name", "hostFolder", "vmFolder", "datastore"}
err := vm.collector.RetrieveOne(vm.ctx, dc.Reference(), ps, &dcMo)
if err != nil {
return nil, NewErrorPropertyRetrieval(dc.Reference(), ps, err)
}
if dcMo.Name == vm.Datacenter {
return &dcMo, err
}
}
return nil, NewErrorObjectNotFound(err, vm.Datacenter)
}
|
go
|
func GetDatacenter(vm *VM) (*mo.Datacenter, error) {
dcList, err := vm.finder.DatacenterList(vm.ctx, "*")
if err != nil {
return nil, NewErrorObjectNotFound(err, vm.Datacenter)
}
for _, dc := range dcList {
dcMo := mo.Datacenter{}
ps := []string{"name", "hostFolder", "vmFolder", "datastore"}
err := vm.collector.RetrieveOne(vm.ctx, dc.Reference(), ps, &dcMo)
if err != nil {
return nil, NewErrorPropertyRetrieval(dc.Reference(), ps, err)
}
if dcMo.Name == vm.Datacenter {
return &dcMo, err
}
}
return nil, NewErrorObjectNotFound(err, vm.Datacenter)
}
|
[
"func",
"GetDatacenter",
"(",
"vm",
"*",
"VM",
")",
"(",
"*",
"mo",
".",
"Datacenter",
",",
"error",
")",
"{",
"dcList",
",",
"err",
":=",
"vm",
".",
"finder",
".",
"DatacenterList",
"(",
"vm",
".",
"ctx",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"NewErrorObjectNotFound",
"(",
"err",
",",
"vm",
".",
"Datacenter",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"dc",
":=",
"range",
"dcList",
"{",
"dcMo",
":=",
"mo",
".",
"Datacenter",
"{",
"}",
"\n",
"ps",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"err",
":=",
"vm",
".",
"collector",
".",
"RetrieveOne",
"(",
"vm",
".",
"ctx",
",",
"dc",
".",
"Reference",
"(",
")",
",",
"ps",
",",
"&",
"dcMo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"NewErrorPropertyRetrieval",
"(",
"dc",
".",
"Reference",
"(",
")",
",",
"ps",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"dcMo",
".",
"Name",
"==",
"vm",
".",
"Datacenter",
"{",
"return",
"&",
"dcMo",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"NewErrorObjectNotFound",
"(",
"err",
",",
"vm",
".",
"Datacenter",
")",
"\n",
"}"
] |
// GetDatacenter retrieves the datacenter that the provisioner was configured
// against.
|
[
"GetDatacenter",
"retrieves",
"the",
"datacenter",
"that",
"the",
"provisioner",
"was",
"configured",
"against",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/util.go#L84-L101
|
146,050 |
apcera/libretto
|
virtualmachine/vsphere/util.go
|
validateHost
|
func validateHost(vm *VM, hsMor types.ManagedObjectReference) (bool, error) {
nwValid := true
dsValid := false
// Fetch the managed object for the host system to populate the datastore and the network folders
hsMo := mo.HostSystem{}
err := vm.collector.RetrieveOne(vm.ctx, hsMor, []string{"network", "datastore"}, &hsMo)
if err != nil {
return false, err
}
hostNetworks := map[string]struct{}{}
for _, nw := range hsMo.Network {
name, err := getNetworkName(vm, nw)
if err != nil {
return false, err
}
if name == "" {
return false, fmt.Errorf("Network name empty for: %s", nw.Value)
}
hostNetworks[name] = struct{}{}
}
for _, v := range vm.Networks {
if _, ok := hostNetworks[v]; !ok {
nwValid = false
break
}
}
for _, ds := range hsMo.Datastore {
dsMo := mo.Datastore{}
err := vm.collector.RetrieveOne(vm.ctx, ds, []string{"name"}, &dsMo)
if err != nil {
return false, err
}
if dsMo.Name == vm.datastore {
dsValid = true
break
}
}
return (nwValid && dsValid), nil
}
|
go
|
func validateHost(vm *VM, hsMor types.ManagedObjectReference) (bool, error) {
nwValid := true
dsValid := false
// Fetch the managed object for the host system to populate the datastore and the network folders
hsMo := mo.HostSystem{}
err := vm.collector.RetrieveOne(vm.ctx, hsMor, []string{"network", "datastore"}, &hsMo)
if err != nil {
return false, err
}
hostNetworks := map[string]struct{}{}
for _, nw := range hsMo.Network {
name, err := getNetworkName(vm, nw)
if err != nil {
return false, err
}
if name == "" {
return false, fmt.Errorf("Network name empty for: %s", nw.Value)
}
hostNetworks[name] = struct{}{}
}
for _, v := range vm.Networks {
if _, ok := hostNetworks[v]; !ok {
nwValid = false
break
}
}
for _, ds := range hsMo.Datastore {
dsMo := mo.Datastore{}
err := vm.collector.RetrieveOne(vm.ctx, ds, []string{"name"}, &dsMo)
if err != nil {
return false, err
}
if dsMo.Name == vm.datastore {
dsValid = true
break
}
}
return (nwValid && dsValid), nil
}
|
[
"func",
"validateHost",
"(",
"vm",
"*",
"VM",
",",
"hsMor",
"types",
".",
"ManagedObjectReference",
")",
"(",
"bool",
",",
"error",
")",
"{",
"nwValid",
":=",
"true",
"\n",
"dsValid",
":=",
"false",
"\n",
"// Fetch the managed object for the host system to populate the datastore and the network folders",
"hsMo",
":=",
"mo",
".",
"HostSystem",
"{",
"}",
"\n",
"err",
":=",
"vm",
".",
"collector",
".",
"RetrieveOne",
"(",
"vm",
".",
"ctx",
",",
"hsMor",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"&",
"hsMo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"hostNetworks",
":=",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
"{",
"}",
"\n",
"for",
"_",
",",
"nw",
":=",
"range",
"hsMo",
".",
"Network",
"{",
"name",
",",
"err",
":=",
"getNetworkName",
"(",
"vm",
",",
"nw",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"name",
"==",
"\"",
"\"",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"nw",
".",
"Value",
")",
"\n",
"}",
"\n",
"hostNetworks",
"[",
"name",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"vm",
".",
"Networks",
"{",
"if",
"_",
",",
"ok",
":=",
"hostNetworks",
"[",
"v",
"]",
";",
"!",
"ok",
"{",
"nwValid",
"=",
"false",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"ds",
":=",
"range",
"hsMo",
".",
"Datastore",
"{",
"dsMo",
":=",
"mo",
".",
"Datastore",
"{",
"}",
"\n",
"err",
":=",
"vm",
".",
"collector",
".",
"RetrieveOne",
"(",
"vm",
".",
"ctx",
",",
"ds",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"&",
"dsMo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"if",
"dsMo",
".",
"Name",
"==",
"vm",
".",
"datastore",
"{",
"dsValid",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"(",
"nwValid",
"&&",
"dsValid",
")",
",",
"nil",
"\n",
"}"
] |
// validateHost validates that the host-system contains the network and the datastore passed in
|
[
"validateHost",
"validates",
"that",
"the",
"host",
"-",
"system",
"contains",
"the",
"network",
"and",
"the",
"datastore",
"passed",
"in"
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/util.go#L736-L775
|
146,051 |
apcera/libretto
|
virtualmachine/vsphere/util.go
|
answerQuestion
|
func (vm *VM) answerQuestion(vmMo *mo.VirtualMachine) error {
q := vmMo.Runtime.Question
if q == nil {
return nil
}
for qre, ans := range vm.QuestionResponses {
if match, err := regexp.MatchString(qre, q.Text); err != nil {
return fmt.Errorf("error while parsing automated responses: %v", err)
} else if match {
ans, validOptions := resolveAnswerAndOptions(q.Choice.ChoiceInfo, ans)
err = answerVSphereQuestion(vm, vmMo, q.Id, ans)
if err != nil {
return fmt.Errorf("error with answer %q to question %q: %v. Valid answers: %v", ans, q.Text, err, validOptions)
}
}
}
return nil
}
|
go
|
func (vm *VM) answerQuestion(vmMo *mo.VirtualMachine) error {
q := vmMo.Runtime.Question
if q == nil {
return nil
}
for qre, ans := range vm.QuestionResponses {
if match, err := regexp.MatchString(qre, q.Text); err != nil {
return fmt.Errorf("error while parsing automated responses: %v", err)
} else if match {
ans, validOptions := resolveAnswerAndOptions(q.Choice.ChoiceInfo, ans)
err = answerVSphereQuestion(vm, vmMo, q.Id, ans)
if err != nil {
return fmt.Errorf("error with answer %q to question %q: %v. Valid answers: %v", ans, q.Text, err, validOptions)
}
}
}
return nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"answerQuestion",
"(",
"vmMo",
"*",
"mo",
".",
"VirtualMachine",
")",
"error",
"{",
"q",
":=",
"vmMo",
".",
"Runtime",
".",
"Question",
"\n",
"if",
"q",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"for",
"qre",
",",
"ans",
":=",
"range",
"vm",
".",
"QuestionResponses",
"{",
"if",
"match",
",",
"err",
":=",
"regexp",
".",
"MatchString",
"(",
"qre",
",",
"q",
".",
"Text",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"if",
"match",
"{",
"ans",
",",
"validOptions",
":=",
"resolveAnswerAndOptions",
"(",
"q",
".",
"Choice",
".",
"ChoiceInfo",
",",
"ans",
")",
"\n",
"err",
"=",
"answerVSphereQuestion",
"(",
"vm",
",",
"vmMo",
",",
"q",
".",
"Id",
",",
"ans",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ans",
",",
"q",
".",
"Text",
",",
"err",
",",
"validOptions",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// answerQuestion checks to see if there are currently pending questions on the
// VM which prevent further actions. If so, it automatically responds to the
// question based on the the vm.QuestionResponses map. If there is a problem
// responding to the question, the error is returned. If there are no pending
// questions or it does not map to any predefined response, nil is returned.
|
[
"answerQuestion",
"checks",
"to",
"see",
"if",
"there",
"are",
"currently",
"pending",
"questions",
"on",
"the",
"VM",
"which",
"prevent",
"further",
"actions",
".",
"If",
"so",
"it",
"automatically",
"responds",
"to",
"the",
"question",
"based",
"on",
"the",
"the",
"vm",
".",
"QuestionResponses",
"map",
".",
"If",
"there",
"is",
"a",
"problem",
"responding",
"to",
"the",
"question",
"the",
"error",
"is",
"returned",
".",
"If",
"there",
"are",
"no",
"pending",
"questions",
"or",
"it",
"does",
"not",
"map",
"to",
"any",
"predefined",
"response",
"nil",
"is",
"returned",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/vsphere/util.go#L796-L815
|
146,052 |
apcera/libretto
|
virtualmachine/exoscale/util.go
|
WaitVMCreation
|
func (vm *VM) WaitVMCreation(timeoutSeconds int, pollIntervalSeconds int) error {
if vm.JobID == "" {
return fmt.Errorf("No JobID informed. Cannot poll machine creation state")
}
jobCh := make(chan *egoscale.QueryAsyncJobResultResponse, 1)
errCh := make(chan error, 1)
go func() {
params := url.Values{}
params.Set("jobid", vm.JobID)
for {
client := vm.getExoClient()
resp, err := client.Request("queryAsyncJobResult", params)
if err != nil {
errCh <- err
}
jobResult := &egoscale.QueryAsyncJobResultResponse{}
err = json.Unmarshal(resp, jobResult)
if err != nil {
errCh <- err
}
if jobResult.Jobstatus == 1 {
jobCh <- jobResult
break
}
time.Sleep(time.Duration(pollIntervalSeconds) * time.Second)
}
}()
select {
case jobResult := <-jobCh:
var vmWrap egoscale.DeployVirtualMachineWrappedResponse
if err := json.Unmarshal(jobResult.Jobresult, &vmWrap); err != nil {
return err
}
vm.ID = vmWrap.Wrapped.Id
case err := <-errCh:
return err
case <-time.After(time.Duration(timeoutSeconds) * time.Second):
return fmt.Errorf("Create VM Job has not completed after %d seconds", timeoutSeconds)
}
return nil
}
|
go
|
func (vm *VM) WaitVMCreation(timeoutSeconds int, pollIntervalSeconds int) error {
if vm.JobID == "" {
return fmt.Errorf("No JobID informed. Cannot poll machine creation state")
}
jobCh := make(chan *egoscale.QueryAsyncJobResultResponse, 1)
errCh := make(chan error, 1)
go func() {
params := url.Values{}
params.Set("jobid", vm.JobID)
for {
client := vm.getExoClient()
resp, err := client.Request("queryAsyncJobResult", params)
if err != nil {
errCh <- err
}
jobResult := &egoscale.QueryAsyncJobResultResponse{}
err = json.Unmarshal(resp, jobResult)
if err != nil {
errCh <- err
}
if jobResult.Jobstatus == 1 {
jobCh <- jobResult
break
}
time.Sleep(time.Duration(pollIntervalSeconds) * time.Second)
}
}()
select {
case jobResult := <-jobCh:
var vmWrap egoscale.DeployVirtualMachineWrappedResponse
if err := json.Unmarshal(jobResult.Jobresult, &vmWrap); err != nil {
return err
}
vm.ID = vmWrap.Wrapped.Id
case err := <-errCh:
return err
case <-time.After(time.Duration(timeoutSeconds) * time.Second):
return fmt.Errorf("Create VM Job has not completed after %d seconds", timeoutSeconds)
}
return nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"WaitVMCreation",
"(",
"timeoutSeconds",
"int",
",",
"pollIntervalSeconds",
"int",
")",
"error",
"{",
"if",
"vm",
".",
"JobID",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"jobCh",
":=",
"make",
"(",
"chan",
"*",
"egoscale",
".",
"QueryAsyncJobResultResponse",
",",
"1",
")",
"\n",
"errCh",
":=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"params",
":=",
"url",
".",
"Values",
"{",
"}",
"\n",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"vm",
".",
"JobID",
")",
"\n\n",
"for",
"{",
"client",
":=",
"vm",
".",
"getExoClient",
"(",
")",
"\n",
"resp",
",",
"err",
":=",
"client",
".",
"Request",
"(",
"\"",
"\"",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errCh",
"<-",
"err",
"\n",
"}",
"\n\n",
"jobResult",
":=",
"&",
"egoscale",
".",
"QueryAsyncJobResultResponse",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"resp",
",",
"jobResult",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errCh",
"<-",
"err",
"\n",
"}",
"\n\n",
"if",
"jobResult",
".",
"Jobstatus",
"==",
"1",
"{",
"jobCh",
"<-",
"jobResult",
"\n",
"break",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"time",
".",
"Duration",
"(",
"pollIntervalSeconds",
")",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"select",
"{",
"case",
"jobResult",
":=",
"<-",
"jobCh",
":",
"var",
"vmWrap",
"egoscale",
".",
"DeployVirtualMachineWrappedResponse",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"jobResult",
".",
"Jobresult",
",",
"&",
"vmWrap",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"vm",
".",
"ID",
"=",
"vmWrap",
".",
"Wrapped",
".",
"Id",
"\n",
"case",
"err",
":=",
"<-",
"errCh",
":",
"return",
"err",
"\n",
"case",
"<-",
"time",
".",
"After",
"(",
"time",
".",
"Duration",
"(",
"timeoutSeconds",
")",
"*",
"time",
".",
"Second",
")",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"timeoutSeconds",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// WaitVMCreation waits for the virtual machine to be created, and stores the virtual machine ID
// VM structure must contain a valid JobID.
|
[
"WaitVMCreation",
"waits",
"for",
"the",
"virtual",
"machine",
"to",
"be",
"created",
"and",
"stores",
"the",
"virtual",
"machine",
"ID",
"VM",
"structure",
"must",
"contain",
"a",
"valid",
"JobID",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/util.go#L20-L68
|
146,053 |
apcera/libretto
|
virtualmachine/exoscale/util.go
|
fillTemplateID
|
func (vm *VM) fillTemplateID() error {
params := url.Values{}
params.Set("Name", vm.Template.Name)
params.Set("templatefilter", "featured")
client := vm.getExoClient()
resp, err := client.Request("listTemplates", params)
if err != nil {
return fmt.Errorf("Getting template ID for '%s/%d/%s': %s", vm.Template.Name, vm.Template.StorageGB, vm.Template.ZoneName, err)
}
templates := &egoscale.ListTemplatesResponse{}
if err := json.Unmarshal(resp, templates); err != nil {
return fmt.Errorf("Decoding response for template '%s/%d/%s': %s", vm.Template.Name, vm.Template.StorageGB, vm.Template.ZoneName, err)
}
// iterate templates to get ID matching size and zone name
storage := int64(vm.Template.StorageGB) << 30
zoneName := strings.ToLower(vm.Template.ZoneName)
for _, template := range templates.Templates {
if template.Size == storage {
if template.Zonename == zoneName {
vm.Template.ID = template.Id
return nil
}
}
}
return fmt.Errorf("Template ID for '%s/%d/%s' could not be found", vm.Template.Name, vm.Template.StorageGB, vm.Template.ZoneName)
}
|
go
|
func (vm *VM) fillTemplateID() error {
params := url.Values{}
params.Set("Name", vm.Template.Name)
params.Set("templatefilter", "featured")
client := vm.getExoClient()
resp, err := client.Request("listTemplates", params)
if err != nil {
return fmt.Errorf("Getting template ID for '%s/%d/%s': %s", vm.Template.Name, vm.Template.StorageGB, vm.Template.ZoneName, err)
}
templates := &egoscale.ListTemplatesResponse{}
if err := json.Unmarshal(resp, templates); err != nil {
return fmt.Errorf("Decoding response for template '%s/%d/%s': %s", vm.Template.Name, vm.Template.StorageGB, vm.Template.ZoneName, err)
}
// iterate templates to get ID matching size and zone name
storage := int64(vm.Template.StorageGB) << 30
zoneName := strings.ToLower(vm.Template.ZoneName)
for _, template := range templates.Templates {
if template.Size == storage {
if template.Zonename == zoneName {
vm.Template.ID = template.Id
return nil
}
}
}
return fmt.Errorf("Template ID for '%s/%d/%s' could not be found", vm.Template.Name, vm.Template.StorageGB, vm.Template.ZoneName)
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"fillTemplateID",
"(",
")",
"error",
"{",
"params",
":=",
"url",
".",
"Values",
"{",
"}",
"\n",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"vm",
".",
"Template",
".",
"Name",
")",
"\n",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"client",
":=",
"vm",
".",
"getExoClient",
"(",
")",
"\n",
"resp",
",",
"err",
":=",
"client",
".",
"Request",
"(",
"\"",
"\"",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vm",
".",
"Template",
".",
"Name",
",",
"vm",
".",
"Template",
".",
"StorageGB",
",",
"vm",
".",
"Template",
".",
"ZoneName",
",",
"err",
")",
"\n",
"}",
"\n\n",
"templates",
":=",
"&",
"egoscale",
".",
"ListTemplatesResponse",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"resp",
",",
"templates",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vm",
".",
"Template",
".",
"Name",
",",
"vm",
".",
"Template",
".",
"StorageGB",
",",
"vm",
".",
"Template",
".",
"ZoneName",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// iterate templates to get ID matching size and zone name",
"storage",
":=",
"int64",
"(",
"vm",
".",
"Template",
".",
"StorageGB",
")",
"<<",
"30",
"\n",
"zoneName",
":=",
"strings",
".",
"ToLower",
"(",
"vm",
".",
"Template",
".",
"ZoneName",
")",
"\n\n",
"for",
"_",
",",
"template",
":=",
"range",
"templates",
".",
"Templates",
"{",
"if",
"template",
".",
"Size",
"==",
"storage",
"{",
"if",
"template",
".",
"Zonename",
"==",
"zoneName",
"{",
"vm",
".",
"Template",
".",
"ID",
"=",
"template",
".",
"Id",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vm",
".",
"Template",
".",
"Name",
",",
"vm",
".",
"Template",
".",
"StorageGB",
",",
"vm",
".",
"Template",
".",
"ZoneName",
")",
"\n",
"}"
] |
// fillTemplateID fills the template identifier based on name, storage and zone name.
// If no matching template is found, ID remains unchanged and an error is returned.
|
[
"fillTemplateID",
"fills",
"the",
"template",
"identifier",
"based",
"on",
"name",
"storage",
"and",
"zone",
"name",
".",
"If",
"no",
"matching",
"template",
"is",
"found",
"ID",
"remains",
"unchanged",
"and",
"an",
"error",
"is",
"returned",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/util.go#L72-L103
|
146,054 |
apcera/libretto
|
virtualmachine/exoscale/util.go
|
fillServiceOfferingID
|
func (vm *VM) fillServiceOfferingID() error {
params := url.Values{}
params.Set("name", strings.ToLower(string(vm.ServiceOffering.Name)))
client := vm.getExoClient()
resp, err := client.Request("listServiceOfferings", params)
if err != nil {
return fmt.Errorf("Getting service offering ID for %q: %s", vm.ServiceOffering.Name, err)
}
so := &egoscale.ListServiceOfferingsResponse{}
if err := json.Unmarshal(resp, so); err != nil {
return fmt.Errorf("Decoding response for service offering %q: %s", vm.ServiceOffering.Name, err)
}
if so.Count != 1 {
return fmt.Errorf("Expected 1 service offering matching %q, but returned %d", vm.ServiceOffering.Name, so.Count)
}
vm.ServiceOffering.ID = so.ServiceOfferings[0].Id
return nil
}
|
go
|
func (vm *VM) fillServiceOfferingID() error {
params := url.Values{}
params.Set("name", strings.ToLower(string(vm.ServiceOffering.Name)))
client := vm.getExoClient()
resp, err := client.Request("listServiceOfferings", params)
if err != nil {
return fmt.Errorf("Getting service offering ID for %q: %s", vm.ServiceOffering.Name, err)
}
so := &egoscale.ListServiceOfferingsResponse{}
if err := json.Unmarshal(resp, so); err != nil {
return fmt.Errorf("Decoding response for service offering %q: %s", vm.ServiceOffering.Name, err)
}
if so.Count != 1 {
return fmt.Errorf("Expected 1 service offering matching %q, but returned %d", vm.ServiceOffering.Name, so.Count)
}
vm.ServiceOffering.ID = so.ServiceOfferings[0].Id
return nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"fillServiceOfferingID",
"(",
")",
"error",
"{",
"params",
":=",
"url",
".",
"Values",
"{",
"}",
"\n",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"strings",
".",
"ToLower",
"(",
"string",
"(",
"vm",
".",
"ServiceOffering",
".",
"Name",
")",
")",
")",
"\n\n",
"client",
":=",
"vm",
".",
"getExoClient",
"(",
")",
"\n",
"resp",
",",
"err",
":=",
"client",
".",
"Request",
"(",
"\"",
"\"",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vm",
".",
"ServiceOffering",
".",
"Name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"so",
":=",
"&",
"egoscale",
".",
"ListServiceOfferingsResponse",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"resp",
",",
"so",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vm",
".",
"ServiceOffering",
".",
"Name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"so",
".",
"Count",
"!=",
"1",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vm",
".",
"ServiceOffering",
".",
"Name",
",",
"so",
".",
"Count",
")",
"\n",
"}",
"\n\n",
"vm",
".",
"ServiceOffering",
".",
"ID",
"=",
"so",
".",
"ServiceOfferings",
"[",
"0",
"]",
".",
"Id",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// fillServiceOfferingID fills the service offering identifier based on name.
// If no matching service offering is found, ID remains unchanged and an error is returned.
|
[
"fillServiceOfferingID",
"fills",
"the",
"service",
"offering",
"identifier",
"based",
"on",
"name",
".",
"If",
"no",
"matching",
"service",
"offering",
"is",
"found",
"ID",
"remains",
"unchanged",
"and",
"an",
"error",
"is",
"returned",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/util.go#L107-L130
|
146,055 |
apcera/libretto
|
virtualmachine/exoscale/util.go
|
fillSecurityGroupsID
|
func (vm *VM) fillSecurityGroupsID() error {
params := url.Values{}
client := vm.getExoClient()
resp, err := client.Request("listSecurityGroups", params)
if err != nil {
return fmt.Errorf("Getting security groups: %s", err)
}
sgRemotes := &egoscale.ListSecurityGroupsResponse{}
if err := json.Unmarshal(resp, sgRemotes); err != nil {
return fmt.Errorf("Decoding response for security groups: %s", err)
}
for i, sg := range vm.SecurityGroups {
if sg.ID != "" {
continue
}
newID := ""
for _, sgRemote := range sgRemotes.SecurityGroups {
if sg.Name == sgRemote.Name {
newID = sgRemote.Id
break
}
}
if newID == "" {
return fmt.Errorf("Could not find security group ID for %q", sg.Name)
}
vm.SecurityGroups[i].ID = newID
}
return nil
}
|
go
|
func (vm *VM) fillSecurityGroupsID() error {
params := url.Values{}
client := vm.getExoClient()
resp, err := client.Request("listSecurityGroups", params)
if err != nil {
return fmt.Errorf("Getting security groups: %s", err)
}
sgRemotes := &egoscale.ListSecurityGroupsResponse{}
if err := json.Unmarshal(resp, sgRemotes); err != nil {
return fmt.Errorf("Decoding response for security groups: %s", err)
}
for i, sg := range vm.SecurityGroups {
if sg.ID != "" {
continue
}
newID := ""
for _, sgRemote := range sgRemotes.SecurityGroups {
if sg.Name == sgRemote.Name {
newID = sgRemote.Id
break
}
}
if newID == "" {
return fmt.Errorf("Could not find security group ID for %q", sg.Name)
}
vm.SecurityGroups[i].ID = newID
}
return nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"fillSecurityGroupsID",
"(",
")",
"error",
"{",
"params",
":=",
"url",
".",
"Values",
"{",
"}",
"\n\n",
"client",
":=",
"vm",
".",
"getExoClient",
"(",
")",
"\n",
"resp",
",",
"err",
":=",
"client",
".",
"Request",
"(",
"\"",
"\"",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"sgRemotes",
":=",
"&",
"egoscale",
".",
"ListSecurityGroupsResponse",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"resp",
",",
"sgRemotes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"i",
",",
"sg",
":=",
"range",
"vm",
".",
"SecurityGroups",
"{",
"if",
"sg",
".",
"ID",
"!=",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n\n",
"newID",
":=",
"\"",
"\"",
"\n",
"for",
"_",
",",
"sgRemote",
":=",
"range",
"sgRemotes",
".",
"SecurityGroups",
"{",
"if",
"sg",
".",
"Name",
"==",
"sgRemote",
".",
"Name",
"{",
"newID",
"=",
"sgRemote",
".",
"Id",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"newID",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sg",
".",
"Name",
")",
"\n",
"}",
"\n",
"vm",
".",
"SecurityGroups",
"[",
"i",
"]",
".",
"ID",
"=",
"newID",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// fillSecurityGroupsID fills the security group identifiers based on name.
// If a security group already has the ID, it will remain unchanged.
// If any of the security groups is not founds error is returned.
|
[
"fillSecurityGroupsID",
"fills",
"the",
"security",
"group",
"identifiers",
"based",
"on",
"name",
".",
"If",
"a",
"security",
"group",
"already",
"has",
"the",
"ID",
"it",
"will",
"remain",
"unchanged",
".",
"If",
"any",
"of",
"the",
"security",
"groups",
"is",
"not",
"founds",
"error",
"is",
"returned",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/util.go#L135-L171
|
146,056 |
apcera/libretto
|
virtualmachine/exoscale/util.go
|
fillZoneID
|
func (vm *VM) fillZoneID() error {
params := url.Values{}
params.Set("name", strings.ToLower(string(vm.Zone.Name)))
client := vm.getExoClient()
resp, err := client.Request("listZones", params)
if err != nil {
return fmt.Errorf("Getting zones ID for %q: %s", vm.ServiceOffering.Name, err)
}
zones := &egoscale.ListZonesResponse{}
if err := json.Unmarshal(resp, zones); err != nil {
return fmt.Errorf("Decoding response for zones list: %s", err)
}
for _, zone := range zones.Zones {
if zone.Name == vm.Zone.Name {
vm.Zone.ID = zone.Id
return nil
}
}
return fmt.Errorf("Zone ID for %q could not be found", vm.Zone.Name)
}
|
go
|
func (vm *VM) fillZoneID() error {
params := url.Values{}
params.Set("name", strings.ToLower(string(vm.Zone.Name)))
client := vm.getExoClient()
resp, err := client.Request("listZones", params)
if err != nil {
return fmt.Errorf("Getting zones ID for %q: %s", vm.ServiceOffering.Name, err)
}
zones := &egoscale.ListZonesResponse{}
if err := json.Unmarshal(resp, zones); err != nil {
return fmt.Errorf("Decoding response for zones list: %s", err)
}
for _, zone := range zones.Zones {
if zone.Name == vm.Zone.Name {
vm.Zone.ID = zone.Id
return nil
}
}
return fmt.Errorf("Zone ID for %q could not be found", vm.Zone.Name)
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"fillZoneID",
"(",
")",
"error",
"{",
"params",
":=",
"url",
".",
"Values",
"{",
"}",
"\n",
"params",
".",
"Set",
"(",
"\"",
"\"",
",",
"strings",
".",
"ToLower",
"(",
"string",
"(",
"vm",
".",
"Zone",
".",
"Name",
")",
")",
")",
"\n\n",
"client",
":=",
"vm",
".",
"getExoClient",
"(",
")",
"\n",
"resp",
",",
"err",
":=",
"client",
".",
"Request",
"(",
"\"",
"\"",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vm",
".",
"ServiceOffering",
".",
"Name",
",",
"err",
")",
"\n",
"}",
"\n\n",
"zones",
":=",
"&",
"egoscale",
".",
"ListZonesResponse",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"resp",
",",
"zones",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"zone",
":=",
"range",
"zones",
".",
"Zones",
"{",
"if",
"zone",
".",
"Name",
"==",
"vm",
".",
"Zone",
".",
"Name",
"{",
"vm",
".",
"Zone",
".",
"ID",
"=",
"zone",
".",
"Id",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vm",
".",
"Zone",
".",
"Name",
")",
"\n",
"}"
] |
// fillZoneID fills the zone identifier based on name.
// If no matching zone is found, ID remains unchanged and an error is returned.
|
[
"fillZoneID",
"fills",
"the",
"zone",
"identifier",
"based",
"on",
"name",
".",
"If",
"no",
"matching",
"zone",
"is",
"found",
"ID",
"remains",
"unchanged",
"and",
"an",
"error",
"is",
"returned",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/exoscale/util.go#L175-L199
|
146,057 |
apcera/libretto
|
virtualmachine/gcp/vm.go
|
Provision
|
func (vm *VM) Provision() error {
s, err := vm.getService()
if err != nil {
return err
}
return s.provision()
}
|
go
|
func (vm *VM) Provision() error {
s, err := vm.getService()
if err != nil {
return err
}
return s.provision()
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"Provision",
"(",
")",
"error",
"{",
"s",
",",
"err",
":=",
"vm",
".",
"getService",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"provision",
"(",
")",
"\n",
"}"
] |
// Provision creates a virtual machine on GCE. It returns an error if
// there was a problem during creation.
|
[
"Provision",
"creates",
"a",
"virtual",
"machine",
"on",
"GCE",
".",
"It",
"returns",
"an",
"error",
"if",
"there",
"was",
"a",
"problem",
"during",
"creation",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/vm.go#L79-L86
|
146,058 |
apcera/libretto
|
virtualmachine/gcp/vm.go
|
GetIPs
|
func (vm *VM) GetIPs() ([]net.IP, error) {
s, err := vm.getService()
if err != nil {
return nil, err
}
return s.getIPs()
}
|
go
|
func (vm *VM) GetIPs() ([]net.IP, error) {
s, err := vm.getService()
if err != nil {
return nil, err
}
return s.getIPs()
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"GetIPs",
"(",
")",
"(",
"[",
"]",
"net",
".",
"IP",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"vm",
".",
"getService",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"getIPs",
"(",
")",
"\n",
"}"
] |
// GetIPs returns a slice of IP addresses assigned to the VM.
|
[
"GetIPs",
"returns",
"a",
"slice",
"of",
"IP",
"addresses",
"assigned",
"to",
"the",
"VM",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/vm.go#L89-L96
|
146,059 |
apcera/libretto
|
virtualmachine/gcp/vm.go
|
Destroy
|
func (vm *VM) Destroy() error {
s, err := vm.getService()
if err != nil {
return err
}
return s.delete()
}
|
go
|
func (vm *VM) Destroy() error {
s, err := vm.getService()
if err != nil {
return err
}
return s.delete()
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"Destroy",
"(",
")",
"error",
"{",
"s",
",",
"err",
":=",
"vm",
".",
"getService",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"delete",
"(",
")",
"\n",
"}"
] |
// Destroy deletes the VM on GCE.
|
[
"Destroy",
"deletes",
"the",
"VM",
"on",
"GCE",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/vm.go#L99-L106
|
146,060 |
apcera/libretto
|
virtualmachine/gcp/vm.go
|
GetState
|
func (vm *VM) GetState() (string, error) {
s, err := vm.getService()
if err != nil {
return "", err
}
instance, err := s.getInstance()
if err != nil {
return "", err
}
switch instance.Status {
case "PROVISIONING", "STAGING":
return virtualmachine.VMStarting, nil
case "RUNNING":
return virtualmachine.VMRunning, nil
case "STOPPING", "STOPPED", "TERMINATED":
return virtualmachine.VMHalted, nil
default:
return virtualmachine.VMUnknown, nil
}
}
|
go
|
func (vm *VM) GetState() (string, error) {
s, err := vm.getService()
if err != nil {
return "", err
}
instance, err := s.getInstance()
if err != nil {
return "", err
}
switch instance.Status {
case "PROVISIONING", "STAGING":
return virtualmachine.VMStarting, nil
case "RUNNING":
return virtualmachine.VMRunning, nil
case "STOPPING", "STOPPED", "TERMINATED":
return virtualmachine.VMHalted, nil
default:
return virtualmachine.VMUnknown, nil
}
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"GetState",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"vm",
".",
"getService",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"instance",
",",
"err",
":=",
"s",
".",
"getInstance",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"switch",
"instance",
".",
"Status",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"virtualmachine",
".",
"VMStarting",
",",
"nil",
"\n",
"case",
"\"",
"\"",
":",
"return",
"virtualmachine",
".",
"VMRunning",
",",
"nil",
"\n",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
":",
"return",
"virtualmachine",
".",
"VMHalted",
",",
"nil",
"\n",
"default",
":",
"return",
"virtualmachine",
".",
"VMUnknown",
",",
"nil",
"\n",
"}",
"\n",
"}"
] |
// GetState retrieve the instance status.
|
[
"GetState",
"retrieve",
"the",
"instance",
"status",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/vm.go#L109-L130
|
146,061 |
apcera/libretto
|
virtualmachine/gcp/vm.go
|
Halt
|
func (vm *VM) Halt() error {
s, err := vm.getService()
if err != nil {
return err
}
return s.stop()
}
|
go
|
func (vm *VM) Halt() error {
s, err := vm.getService()
if err != nil {
return err
}
return s.stop()
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"Halt",
"(",
")",
"error",
"{",
"s",
",",
"err",
":=",
"vm",
".",
"getService",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"stop",
"(",
")",
"\n",
"}"
] |
// Halt stops a GCE instance.
|
[
"Halt",
"stops",
"a",
"GCE",
"instance",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/vm.go#L143-L150
|
146,062 |
apcera/libretto
|
virtualmachine/gcp/vm.go
|
Start
|
func (vm *VM) Start() error {
s, err := vm.getService()
if err != nil {
return err
}
return s.start()
}
|
go
|
func (vm *VM) Start() error {
s, err := vm.getService()
if err != nil {
return err
}
return s.start()
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"Start",
"(",
")",
"error",
"{",
"s",
",",
"err",
":=",
"vm",
".",
"getService",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"start",
"(",
")",
"\n",
"}"
] |
// Start a stopped GCE instance.
|
[
"Start",
"a",
"stopped",
"GCE",
"instance",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/vm.go#L153-L160
|
146,063 |
apcera/libretto
|
virtualmachine/gcp/vm.go
|
InsertSSHKey
|
func (vm *VM) InsertSSHKey(publicKey string) error {
s, err := vm.getService()
if err != nil {
return err
}
return s.insertSSHKey()
}
|
go
|
func (vm *VM) InsertSSHKey(publicKey string) error {
s, err := vm.getService()
if err != nil {
return err
}
return s.insertSSHKey()
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"InsertSSHKey",
"(",
"publicKey",
"string",
")",
"error",
"{",
"s",
",",
"err",
":=",
"vm",
".",
"getService",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"s",
".",
"insertSSHKey",
"(",
")",
"\n",
"}"
] |
// InsertSSHKey uploads new ssh key into the GCE instance.
|
[
"InsertSSHKey",
"uploads",
"new",
"ssh",
"key",
"into",
"the",
"GCE",
"instance",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/vm.go#L184-L191
|
146,064 |
apcera/libretto
|
virtualmachine/gcp/vm.go
|
DeleteDisks
|
func (vm *VM) DeleteDisks() error {
s, err := vm.getService()
if err != nil {
return err
}
errs := s.deleteDisks()
if len(errs) > 0 {
err = util.CombineErrors(": ", errs...)
return err
}
return nil
}
|
go
|
func (vm *VM) DeleteDisks() error {
s, err := vm.getService()
if err != nil {
return err
}
errs := s.deleteDisks()
if len(errs) > 0 {
err = util.CombineErrors(": ", errs...)
return err
}
return nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"DeleteDisks",
"(",
")",
"error",
"{",
"s",
",",
"err",
":=",
"vm",
".",
"getService",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"errs",
":=",
"s",
".",
"deleteDisks",
"(",
")",
"\n",
"if",
"len",
"(",
"errs",
")",
">",
"0",
"{",
"err",
"=",
"util",
".",
"CombineErrors",
"(",
"\"",
"\"",
",",
"errs",
"...",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// DeleteDisks cleans up all the disks attached to the GCE instance.
|
[
"DeleteDisks",
"cleans",
"up",
"all",
"the",
"disks",
"attached",
"to",
"the",
"GCE",
"instance",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/gcp/vm.go#L194-L207
|
146,065 |
apcera/libretto
|
virtualmachine/azure/arm/util.go
|
getServicePrincipalToken
|
func getServicePrincipalToken(creds *OAuthCredentials, scope string) (*adal.ServicePrincipalToken, error) {
oauthConfig, err := adal.NewOAuthConfig(azure.PublicCloud.ActiveDirectoryEndpoint, creds.TenantID)
if err != nil {
return nil, err
}
return adal.NewServicePrincipalToken(*oauthConfig, creds.ClientID, creds.ClientSecret, scope)
}
|
go
|
func getServicePrincipalToken(creds *OAuthCredentials, scope string) (*adal.ServicePrincipalToken, error) {
oauthConfig, err := adal.NewOAuthConfig(azure.PublicCloud.ActiveDirectoryEndpoint, creds.TenantID)
if err != nil {
return nil, err
}
return adal.NewServicePrincipalToken(*oauthConfig, creds.ClientID, creds.ClientSecret, scope)
}
|
[
"func",
"getServicePrincipalToken",
"(",
"creds",
"*",
"OAuthCredentials",
",",
"scope",
"string",
")",
"(",
"*",
"adal",
".",
"ServicePrincipalToken",
",",
"error",
")",
"{",
"oauthConfig",
",",
"err",
":=",
"adal",
".",
"NewOAuthConfig",
"(",
"azure",
".",
"PublicCloud",
".",
"ActiveDirectoryEndpoint",
",",
"creds",
".",
"TenantID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"adal",
".",
"NewServicePrincipalToken",
"(",
"*",
"oauthConfig",
",",
"creds",
".",
"ClientID",
",",
"creds",
".",
"ClientSecret",
",",
"scope",
")",
"\n",
"}"
] |
// getServicePrincipalToken retrieves a new ServicePrincipalToken using values of the
// passed credentials map.
|
[
"getServicePrincipalToken",
"retrieves",
"a",
"new",
"ServicePrincipalToken",
"using",
"values",
"of",
"the",
"passed",
"credentials",
"map",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/arm/util.go#L26-L32
|
146,066 |
apcera/libretto
|
virtualmachine/azure/arm/util.go
|
toARMParameters
|
func (vm *VM) toARMParameters() *armParameters {
out := &armParameters{
AdminUsername: &armParameter{vm.SSHCreds.SSHUser},
AdminPassword: &armParameter{vm.SSHCreds.SSHPassword},
ImageOffer: &armParameter{vm.ImageOffer},
ImagePublisher: &armParameter{vm.ImagePublisher},
ImageSku: &armParameter{vm.ImageSku},
NetworkSecurityGroup: &armParameter{vm.NetworkSecurityGroup},
NicName: &armParameter{vm.Nic},
OSFileName: &armParameter{vm.OsFile},
PublicIPName: &armParameter{vm.PublicIP},
SSHAuthorizedKey: &armParameter{vm.SSHPublicKey},
StorageAccountName: &armParameter{vm.StorageAccount},
StorageContainerName: &armParameter{vm.StorageContainer},
SubnetName: &armParameter{vm.Subnet},
VirtualNetworkName: &armParameter{vm.VirtualNetwork},
VMSize: &armParameter{vm.Size},
VMName: &armParameter{vm.Name},
DiskSize: &armParameter{strconv.Itoa(vm.DiskSize)},
DiskFile: &armParameter{vm.DiskFile},
AdditionalDisk: &armParameter{"false"},
}
if vm.DiskSize > 0 {
out.AdditionalDisk = &armParameter{"true"}
}
return out
}
|
go
|
func (vm *VM) toARMParameters() *armParameters {
out := &armParameters{
AdminUsername: &armParameter{vm.SSHCreds.SSHUser},
AdminPassword: &armParameter{vm.SSHCreds.SSHPassword},
ImageOffer: &armParameter{vm.ImageOffer},
ImagePublisher: &armParameter{vm.ImagePublisher},
ImageSku: &armParameter{vm.ImageSku},
NetworkSecurityGroup: &armParameter{vm.NetworkSecurityGroup},
NicName: &armParameter{vm.Nic},
OSFileName: &armParameter{vm.OsFile},
PublicIPName: &armParameter{vm.PublicIP},
SSHAuthorizedKey: &armParameter{vm.SSHPublicKey},
StorageAccountName: &armParameter{vm.StorageAccount},
StorageContainerName: &armParameter{vm.StorageContainer},
SubnetName: &armParameter{vm.Subnet},
VirtualNetworkName: &armParameter{vm.VirtualNetwork},
VMSize: &armParameter{vm.Size},
VMName: &armParameter{vm.Name},
DiskSize: &armParameter{strconv.Itoa(vm.DiskSize)},
DiskFile: &armParameter{vm.DiskFile},
AdditionalDisk: &armParameter{"false"},
}
if vm.DiskSize > 0 {
out.AdditionalDisk = &armParameter{"true"}
}
return out
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"toARMParameters",
"(",
")",
"*",
"armParameters",
"{",
"out",
":=",
"&",
"armParameters",
"{",
"AdminUsername",
":",
"&",
"armParameter",
"{",
"vm",
".",
"SSHCreds",
".",
"SSHUser",
"}",
",",
"AdminPassword",
":",
"&",
"armParameter",
"{",
"vm",
".",
"SSHCreds",
".",
"SSHPassword",
"}",
",",
"ImageOffer",
":",
"&",
"armParameter",
"{",
"vm",
".",
"ImageOffer",
"}",
",",
"ImagePublisher",
":",
"&",
"armParameter",
"{",
"vm",
".",
"ImagePublisher",
"}",
",",
"ImageSku",
":",
"&",
"armParameter",
"{",
"vm",
".",
"ImageSku",
"}",
",",
"NetworkSecurityGroup",
":",
"&",
"armParameter",
"{",
"vm",
".",
"NetworkSecurityGroup",
"}",
",",
"NicName",
":",
"&",
"armParameter",
"{",
"vm",
".",
"Nic",
"}",
",",
"OSFileName",
":",
"&",
"armParameter",
"{",
"vm",
".",
"OsFile",
"}",
",",
"PublicIPName",
":",
"&",
"armParameter",
"{",
"vm",
".",
"PublicIP",
"}",
",",
"SSHAuthorizedKey",
":",
"&",
"armParameter",
"{",
"vm",
".",
"SSHPublicKey",
"}",
",",
"StorageAccountName",
":",
"&",
"armParameter",
"{",
"vm",
".",
"StorageAccount",
"}",
",",
"StorageContainerName",
":",
"&",
"armParameter",
"{",
"vm",
".",
"StorageContainer",
"}",
",",
"SubnetName",
":",
"&",
"armParameter",
"{",
"vm",
".",
"Subnet",
"}",
",",
"VirtualNetworkName",
":",
"&",
"armParameter",
"{",
"vm",
".",
"VirtualNetwork",
"}",
",",
"VMSize",
":",
"&",
"armParameter",
"{",
"vm",
".",
"Size",
"}",
",",
"VMName",
":",
"&",
"armParameter",
"{",
"vm",
".",
"Name",
"}",
",",
"DiskSize",
":",
"&",
"armParameter",
"{",
"strconv",
".",
"Itoa",
"(",
"vm",
".",
"DiskSize",
")",
"}",
",",
"DiskFile",
":",
"&",
"armParameter",
"{",
"vm",
".",
"DiskFile",
"}",
",",
"AdditionalDisk",
":",
"&",
"armParameter",
"{",
"\"",
"\"",
"}",
",",
"}",
"\n\n",
"if",
"vm",
".",
"DiskSize",
">",
"0",
"{",
"out",
".",
"AdditionalDisk",
"=",
"&",
"armParameter",
"{",
"\"",
"\"",
"}",
"\n",
"}",
"\n\n",
"return",
"out",
"\n",
"}"
] |
// Translates the given VM to arm parameters
|
[
"Translates",
"the",
"given",
"VM",
"to",
"arm",
"parameters"
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/arm/util.go#L61-L89
|
146,067 |
apcera/libretto
|
virtualmachine/azure/arm/util.go
|
validateVM
|
func validateVM(vm *VM) error {
// Validate the OAUTH Credentials
if vm.Creds.ClientID == "" {
return fmt.Errorf("a client id must be specified")
}
if vm.Creds.ClientSecret == "" {
return fmt.Errorf("a client secret must be specified")
}
if vm.Creds.TenantID == "" {
return fmt.Errorf("a tenant id must be specified")
}
if vm.Creds.SubscriptionID == "" {
return fmt.Errorf("a subscription id must be specified")
}
// Validate the image
if vm.ImagePublisher == "" {
return fmt.Errorf("an image publisher must be specified")
}
if vm.ImageOffer == "" {
return fmt.Errorf("an image offer must be specified")
}
if vm.ImageSku == "" {
return fmt.Errorf("an image sku must be specified")
}
// Validate the deployment
if vm.ResourceGroup == "" {
return fmt.Errorf("a resource group must be specified")
}
if vm.StorageAccount == "" {
return fmt.Errorf("a storage account must be specified")
}
// Validate the network
if vm.NetworkSecurityGroup == "" {
return fmt.Errorf("a network security group must be specified")
}
if vm.Subnet == "" {
return fmt.Errorf("a subnet must be specified")
}
if vm.VirtualNetwork == "" {
return fmt.Errorf("a virtual network must be specified")
}
return nil
}
|
go
|
func validateVM(vm *VM) error {
// Validate the OAUTH Credentials
if vm.Creds.ClientID == "" {
return fmt.Errorf("a client id must be specified")
}
if vm.Creds.ClientSecret == "" {
return fmt.Errorf("a client secret must be specified")
}
if vm.Creds.TenantID == "" {
return fmt.Errorf("a tenant id must be specified")
}
if vm.Creds.SubscriptionID == "" {
return fmt.Errorf("a subscription id must be specified")
}
// Validate the image
if vm.ImagePublisher == "" {
return fmt.Errorf("an image publisher must be specified")
}
if vm.ImageOffer == "" {
return fmt.Errorf("an image offer must be specified")
}
if vm.ImageSku == "" {
return fmt.Errorf("an image sku must be specified")
}
// Validate the deployment
if vm.ResourceGroup == "" {
return fmt.Errorf("a resource group must be specified")
}
if vm.StorageAccount == "" {
return fmt.Errorf("a storage account must be specified")
}
// Validate the network
if vm.NetworkSecurityGroup == "" {
return fmt.Errorf("a network security group must be specified")
}
if vm.Subnet == "" {
return fmt.Errorf("a subnet must be specified")
}
if vm.VirtualNetwork == "" {
return fmt.Errorf("a virtual network must be specified")
}
return nil
}
|
[
"func",
"validateVM",
"(",
"vm",
"*",
"VM",
")",
"error",
"{",
"// Validate the OAUTH Credentials",
"if",
"vm",
".",
"Creds",
".",
"ClientID",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"vm",
".",
"Creds",
".",
"ClientSecret",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"vm",
".",
"Creds",
".",
"TenantID",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"vm",
".",
"Creds",
".",
"SubscriptionID",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate the image",
"if",
"vm",
".",
"ImagePublisher",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"vm",
".",
"ImageOffer",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"vm",
".",
"ImageSku",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate the deployment",
"if",
"vm",
".",
"ResourceGroup",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"vm",
".",
"StorageAccount",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Validate the network",
"if",
"vm",
".",
"NetworkSecurityGroup",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"vm",
".",
"Subnet",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"vm",
".",
"VirtualNetwork",
"==",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// validateVM validates the members of given VM object
|
[
"validateVM",
"validates",
"the",
"members",
"of",
"given",
"VM",
"object"
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/arm/util.go#L92-L146
|
146,068 |
apcera/libretto
|
virtualmachine/azure/arm/util.go
|
deploy
|
func (vm *VM) deploy() error {
// Get the auth token.
tok, err := getServicePrincipalToken(&vm.Creds, azure.PublicCloud.ResourceManagerEndpoint)
if err != nil {
return err
}
// Pass the parameters to the arm templacte
vmParams := vm.toARMParameters()
deployment, err := createDeployment(Linux, *vmParams)
if err != nil {
return err
}
// Create and send the deployment to the resource group
deploymentsClient := resources.NewDeploymentsClient(vm.Creds.SubscriptionID)
deploymentsClient.Authorizer = autorest.NewBearerAuthorizer(tok)
_, errc := deploymentsClient.CreateOrUpdate(vm.ResourceGroup, vm.DeploymentName, *deployment, nil)
if err := <-errc; err != nil {
return err
}
// Make sure the deployment is succeeded
for i := 0; i < actionTimeout; i++ {
result, err := deploymentsClient.Get(vm.ResourceGroup, vm.DeploymentName)
if err != nil {
return err
}
if result.Properties != nil && result.Properties.ProvisioningState != nil {
if *result.Properties.ProvisioningState == succeeded {
return nil
}
}
time.Sleep(1 * time.Second)
}
return ErrActionTimeout
}
|
go
|
func (vm *VM) deploy() error {
// Get the auth token.
tok, err := getServicePrincipalToken(&vm.Creds, azure.PublicCloud.ResourceManagerEndpoint)
if err != nil {
return err
}
// Pass the parameters to the arm templacte
vmParams := vm.toARMParameters()
deployment, err := createDeployment(Linux, *vmParams)
if err != nil {
return err
}
// Create and send the deployment to the resource group
deploymentsClient := resources.NewDeploymentsClient(vm.Creds.SubscriptionID)
deploymentsClient.Authorizer = autorest.NewBearerAuthorizer(tok)
_, errc := deploymentsClient.CreateOrUpdate(vm.ResourceGroup, vm.DeploymentName, *deployment, nil)
if err := <-errc; err != nil {
return err
}
// Make sure the deployment is succeeded
for i := 0; i < actionTimeout; i++ {
result, err := deploymentsClient.Get(vm.ResourceGroup, vm.DeploymentName)
if err != nil {
return err
}
if result.Properties != nil && result.Properties.ProvisioningState != nil {
if *result.Properties.ProvisioningState == succeeded {
return nil
}
}
time.Sleep(1 * time.Second)
}
return ErrActionTimeout
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"deploy",
"(",
")",
"error",
"{",
"// Get the auth token.",
"tok",
",",
"err",
":=",
"getServicePrincipalToken",
"(",
"&",
"vm",
".",
"Creds",
",",
"azure",
".",
"PublicCloud",
".",
"ResourceManagerEndpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Pass the parameters to the arm templacte",
"vmParams",
":=",
"vm",
".",
"toARMParameters",
"(",
")",
"\n",
"deployment",
",",
"err",
":=",
"createDeployment",
"(",
"Linux",
",",
"*",
"vmParams",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Create and send the deployment to the resource group",
"deploymentsClient",
":=",
"resources",
".",
"NewDeploymentsClient",
"(",
"vm",
".",
"Creds",
".",
"SubscriptionID",
")",
"\n",
"deploymentsClient",
".",
"Authorizer",
"=",
"autorest",
".",
"NewBearerAuthorizer",
"(",
"tok",
")",
"\n\n",
"_",
",",
"errc",
":=",
"deploymentsClient",
".",
"CreateOrUpdate",
"(",
"vm",
".",
"ResourceGroup",
",",
"vm",
".",
"DeploymentName",
",",
"*",
"deployment",
",",
"nil",
")",
"\n",
"if",
"err",
":=",
"<-",
"errc",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Make sure the deployment is succeeded",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"actionTimeout",
";",
"i",
"++",
"{",
"result",
",",
"err",
":=",
"deploymentsClient",
".",
"Get",
"(",
"vm",
".",
"ResourceGroup",
",",
"vm",
".",
"DeploymentName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"result",
".",
"Properties",
"!=",
"nil",
"&&",
"result",
".",
"Properties",
".",
"ProvisioningState",
"!=",
"nil",
"{",
"if",
"*",
"result",
".",
"Properties",
".",
"ProvisioningState",
"==",
"succeeded",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"1",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n\n",
"return",
"ErrActionTimeout",
"\n",
"}"
] |
// deploy deploys the given VM based on the default Linux arm template over the
// VM's resource group.
|
[
"deploy",
"deploys",
"the",
"given",
"VM",
"based",
"on",
"the",
"default",
"Linux",
"arm",
"template",
"over",
"the",
"VM",
"s",
"resource",
"group",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/arm/util.go#L150-L189
|
146,069 |
apcera/libretto
|
virtualmachine/azure/arm/util.go
|
getPublicIP
|
func (vm *VM) getPublicIP(authorizer autorest.Authorizer) (net.IP, error) {
publicIPAddressesClient := network.NewPublicIPAddressesClient(vm.Creds.SubscriptionID)
publicIPAddressesClient.Authorizer = authorizer
resPublicIP, err := publicIPAddressesClient.Get(vm.ResourceGroup, vm.PublicIP, "")
if err != nil {
return nil, err
}
if resPublicIP.PublicIPAddressPropertiesFormat == nil || resPublicIP.PublicIPAddressPropertiesFormat.IPAddress == nil ||
*resPublicIP.PublicIPAddressPropertiesFormat.IPAddress == "" {
return nil, fmt.Errorf("VM has no public IP address")
}
return net.ParseIP(*resPublicIP.PublicIPAddressPropertiesFormat.IPAddress), nil
}
|
go
|
func (vm *VM) getPublicIP(authorizer autorest.Authorizer) (net.IP, error) {
publicIPAddressesClient := network.NewPublicIPAddressesClient(vm.Creds.SubscriptionID)
publicIPAddressesClient.Authorizer = authorizer
resPublicIP, err := publicIPAddressesClient.Get(vm.ResourceGroup, vm.PublicIP, "")
if err != nil {
return nil, err
}
if resPublicIP.PublicIPAddressPropertiesFormat == nil || resPublicIP.PublicIPAddressPropertiesFormat.IPAddress == nil ||
*resPublicIP.PublicIPAddressPropertiesFormat.IPAddress == "" {
return nil, fmt.Errorf("VM has no public IP address")
}
return net.ParseIP(*resPublicIP.PublicIPAddressPropertiesFormat.IPAddress), nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"getPublicIP",
"(",
"authorizer",
"autorest",
".",
"Authorizer",
")",
"(",
"net",
".",
"IP",
",",
"error",
")",
"{",
"publicIPAddressesClient",
":=",
"network",
".",
"NewPublicIPAddressesClient",
"(",
"vm",
".",
"Creds",
".",
"SubscriptionID",
")",
"\n",
"publicIPAddressesClient",
".",
"Authorizer",
"=",
"authorizer",
"\n\n",
"resPublicIP",
",",
"err",
":=",
"publicIPAddressesClient",
".",
"Get",
"(",
"vm",
".",
"ResourceGroup",
",",
"vm",
".",
"PublicIP",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"resPublicIP",
".",
"PublicIPAddressPropertiesFormat",
"==",
"nil",
"||",
"resPublicIP",
".",
"PublicIPAddressPropertiesFormat",
".",
"IPAddress",
"==",
"nil",
"||",
"*",
"resPublicIP",
".",
"PublicIPAddressPropertiesFormat",
".",
"IPAddress",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"net",
".",
"ParseIP",
"(",
"*",
"resPublicIP",
".",
"PublicIPAddressPropertiesFormat",
".",
"IPAddress",
")",
",",
"nil",
"\n",
"}"
] |
// getPublicIP returns the public IP of the given VM, if exists one.
|
[
"getPublicIP",
"returns",
"the",
"public",
"IP",
"of",
"the",
"given",
"VM",
"if",
"exists",
"one",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/arm/util.go#L192-L206
|
146,070 |
apcera/libretto
|
virtualmachine/azure/arm/util.go
|
getPrivateIP
|
func (vm *VM) getPrivateIP(authorizer autorest.Authorizer) (net.IP, error) {
interfaceClient := network.NewInterfacesClient(vm.Creds.SubscriptionID)
interfaceClient.Authorizer = authorizer
iface, err := interfaceClient.Get(vm.ResourceGroup, vm.Nic, "")
if err != nil {
return nil, err
}
if iface.InterfacePropertiesFormat == nil || iface.InterfacePropertiesFormat.IPConfigurations == nil ||
len(*iface.InterfacePropertiesFormat.IPConfigurations) == 0 {
return nil, fmt.Errorf("VM has no private IP address")
}
ipConfigs := *iface.InterfacePropertiesFormat.IPConfigurations
if len(ipConfigs) > 1 {
return nil, fmt.Errorf("VM has multiple private IP addresses")
}
return net.ParseIP(*ipConfigs[0].InterfaceIPConfigurationPropertiesFormat.PrivateIPAddress), nil
}
|
go
|
func (vm *VM) getPrivateIP(authorizer autorest.Authorizer) (net.IP, error) {
interfaceClient := network.NewInterfacesClient(vm.Creds.SubscriptionID)
interfaceClient.Authorizer = authorizer
iface, err := interfaceClient.Get(vm.ResourceGroup, vm.Nic, "")
if err != nil {
return nil, err
}
if iface.InterfacePropertiesFormat == nil || iface.InterfacePropertiesFormat.IPConfigurations == nil ||
len(*iface.InterfacePropertiesFormat.IPConfigurations) == 0 {
return nil, fmt.Errorf("VM has no private IP address")
}
ipConfigs := *iface.InterfacePropertiesFormat.IPConfigurations
if len(ipConfigs) > 1 {
return nil, fmt.Errorf("VM has multiple private IP addresses")
}
return net.ParseIP(*ipConfigs[0].InterfaceIPConfigurationPropertiesFormat.PrivateIPAddress), nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"getPrivateIP",
"(",
"authorizer",
"autorest",
".",
"Authorizer",
")",
"(",
"net",
".",
"IP",
",",
"error",
")",
"{",
"interfaceClient",
":=",
"network",
".",
"NewInterfacesClient",
"(",
"vm",
".",
"Creds",
".",
"SubscriptionID",
")",
"\n",
"interfaceClient",
".",
"Authorizer",
"=",
"authorizer",
"\n\n",
"iface",
",",
"err",
":=",
"interfaceClient",
".",
"Get",
"(",
"vm",
".",
"ResourceGroup",
",",
"vm",
".",
"Nic",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"iface",
".",
"InterfacePropertiesFormat",
"==",
"nil",
"||",
"iface",
".",
"InterfacePropertiesFormat",
".",
"IPConfigurations",
"==",
"nil",
"||",
"len",
"(",
"*",
"iface",
".",
"InterfacePropertiesFormat",
".",
"IPConfigurations",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ipConfigs",
":=",
"*",
"iface",
".",
"InterfacePropertiesFormat",
".",
"IPConfigurations",
"\n",
"if",
"len",
"(",
"ipConfigs",
")",
">",
"1",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"net",
".",
"ParseIP",
"(",
"*",
"ipConfigs",
"[",
"0",
"]",
".",
"InterfaceIPConfigurationPropertiesFormat",
".",
"PrivateIPAddress",
")",
",",
"nil",
"\n",
"}"
] |
// getPrivateIP returns the private IP of the given VM, if exists one.
|
[
"getPrivateIP",
"returns",
"the",
"private",
"IP",
"of",
"the",
"given",
"VM",
"if",
"exists",
"one",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/arm/util.go#L209-L227
|
146,071 |
apcera/libretto
|
virtualmachine/azure/arm/util.go
|
deleteVMFiles
|
func (vm *VM) deleteVMFiles(authorizer autorest.Authorizer) error {
storageAccountsClient := armStorage.NewAccountsClient(vm.Creds.SubscriptionID)
storageAccountsClient.Authorizer = authorizer
result, err := storageAccountsClient.ListKeys(vm.ResourceGroup, vm.StorageAccount)
if err != nil {
return err
}
accountKeys := result.Keys
if accountKeys == nil || len(*accountKeys) == 0 {
return fmt.Errorf("no account keys for storage account %q", vm.StorageAccount)
}
accountKey := *(*accountKeys)[0].Value
storageClient, err := storage.NewBasicClient(vm.StorageAccount, accountKey)
if err != nil {
return err
}
// Get a reference to the OS file.
blobStorageClient := storageClient.GetBlobService()
container := blobStorageClient.GetContainerReference(vm.StorageContainer)
osFileBlob := container.GetBlobReference(vm.OsFile)
// Delete the OS file.
opts := &storage.DeleteBlobOptions{Timeout: 30} // 30s timeout
err = osFileBlob.Delete(opts)
if vm.DiskSize <= 0 {
return err
}
// Delete the disk file.
diskFileBlob := container.GetBlobReference(vm.DiskFile)
diskFileErr := diskFileBlob.Delete(opts)
if err != nil {
return fmt.Errorf("failed to delete OS file and disk file: %v, %v", err, diskFileErr)
}
return diskFileErr
}
|
go
|
func (vm *VM) deleteVMFiles(authorizer autorest.Authorizer) error {
storageAccountsClient := armStorage.NewAccountsClient(vm.Creds.SubscriptionID)
storageAccountsClient.Authorizer = authorizer
result, err := storageAccountsClient.ListKeys(vm.ResourceGroup, vm.StorageAccount)
if err != nil {
return err
}
accountKeys := result.Keys
if accountKeys == nil || len(*accountKeys) == 0 {
return fmt.Errorf("no account keys for storage account %q", vm.StorageAccount)
}
accountKey := *(*accountKeys)[0].Value
storageClient, err := storage.NewBasicClient(vm.StorageAccount, accountKey)
if err != nil {
return err
}
// Get a reference to the OS file.
blobStorageClient := storageClient.GetBlobService()
container := blobStorageClient.GetContainerReference(vm.StorageContainer)
osFileBlob := container.GetBlobReference(vm.OsFile)
// Delete the OS file.
opts := &storage.DeleteBlobOptions{Timeout: 30} // 30s timeout
err = osFileBlob.Delete(opts)
if vm.DiskSize <= 0 {
return err
}
// Delete the disk file.
diskFileBlob := container.GetBlobReference(vm.DiskFile)
diskFileErr := diskFileBlob.Delete(opts)
if err != nil {
return fmt.Errorf("failed to delete OS file and disk file: %v, %v", err, diskFileErr)
}
return diskFileErr
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"deleteVMFiles",
"(",
"authorizer",
"autorest",
".",
"Authorizer",
")",
"error",
"{",
"storageAccountsClient",
":=",
"armStorage",
".",
"NewAccountsClient",
"(",
"vm",
".",
"Creds",
".",
"SubscriptionID",
")",
"\n",
"storageAccountsClient",
".",
"Authorizer",
"=",
"authorizer",
"\n\n",
"result",
",",
"err",
":=",
"storageAccountsClient",
".",
"ListKeys",
"(",
"vm",
".",
"ResourceGroup",
",",
"vm",
".",
"StorageAccount",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"accountKeys",
":=",
"result",
".",
"Keys",
"\n",
"if",
"accountKeys",
"==",
"nil",
"||",
"len",
"(",
"*",
"accountKeys",
")",
"==",
"0",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vm",
".",
"StorageAccount",
")",
"\n",
"}",
"\n\n",
"accountKey",
":=",
"*",
"(",
"*",
"accountKeys",
")",
"[",
"0",
"]",
".",
"Value",
"\n",
"storageClient",
",",
"err",
":=",
"storage",
".",
"NewBasicClient",
"(",
"vm",
".",
"StorageAccount",
",",
"accountKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Get a reference to the OS file.",
"blobStorageClient",
":=",
"storageClient",
".",
"GetBlobService",
"(",
")",
"\n",
"container",
":=",
"blobStorageClient",
".",
"GetContainerReference",
"(",
"vm",
".",
"StorageContainer",
")",
"\n",
"osFileBlob",
":=",
"container",
".",
"GetBlobReference",
"(",
"vm",
".",
"OsFile",
")",
"\n\n",
"// Delete the OS file.",
"opts",
":=",
"&",
"storage",
".",
"DeleteBlobOptions",
"{",
"Timeout",
":",
"30",
"}",
"// 30s timeout",
"\n",
"err",
"=",
"osFileBlob",
".",
"Delete",
"(",
"opts",
")",
"\n\n",
"if",
"vm",
".",
"DiskSize",
"<=",
"0",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Delete the disk file.",
"diskFileBlob",
":=",
"container",
".",
"GetBlobReference",
"(",
"vm",
".",
"DiskFile",
")",
"\n",
"diskFileErr",
":=",
"diskFileBlob",
".",
"Delete",
"(",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
",",
"diskFileErr",
")",
"\n",
"}",
"\n\n",
"return",
"diskFileErr",
"\n",
"}"
] |
// deleteOSFile deletes the OS file from the VM's storage account, returns an error if the operation
// does not succeed.
|
[
"deleteOSFile",
"deletes",
"the",
"OS",
"file",
"from",
"the",
"VM",
"s",
"storage",
"account",
"returns",
"an",
"error",
"if",
"the",
"operation",
"does",
"not",
"succeed",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/arm/util.go#L231-L272
|
146,072 |
apcera/libretto
|
virtualmachine/azure/arm/util.go
|
deleteNic
|
func (vm *VM) deleteNic(authorizer autorest.Authorizer) error {
interfaceClient := network.NewInterfacesClient(vm.Creds.SubscriptionID)
interfaceClient.Authorizer = authorizer
_, errc := interfaceClient.Delete(vm.ResourceGroup, vm.Nic, nil)
return <-errc
}
|
go
|
func (vm *VM) deleteNic(authorizer autorest.Authorizer) error {
interfaceClient := network.NewInterfacesClient(vm.Creds.SubscriptionID)
interfaceClient.Authorizer = authorizer
_, errc := interfaceClient.Delete(vm.ResourceGroup, vm.Nic, nil)
return <-errc
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"deleteNic",
"(",
"authorizer",
"autorest",
".",
"Authorizer",
")",
"error",
"{",
"interfaceClient",
":=",
"network",
".",
"NewInterfacesClient",
"(",
"vm",
".",
"Creds",
".",
"SubscriptionID",
")",
"\n",
"interfaceClient",
".",
"Authorizer",
"=",
"authorizer",
"\n\n",
"_",
",",
"errc",
":=",
"interfaceClient",
".",
"Delete",
"(",
"vm",
".",
"ResourceGroup",
",",
"vm",
".",
"Nic",
",",
"nil",
")",
"\n",
"return",
"<-",
"errc",
"\n",
"}"
] |
// deleteNic deletes the network interface for the given VM from the VM's resource group, returns an error
// if the operation does not succeed.
|
[
"deleteNic",
"deletes",
"the",
"network",
"interface",
"for",
"the",
"given",
"VM",
"from",
"the",
"VM",
"s",
"resource",
"group",
"returns",
"an",
"error",
"if",
"the",
"operation",
"does",
"not",
"succeed",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/arm/util.go#L276-L282
|
146,073 |
apcera/libretto
|
virtualmachine/azure/arm/util.go
|
deletePublicIP
|
func (vm *VM) deletePublicIP(authorizer autorest.Authorizer) error {
// Delete the Public IP of this VM
publicIPAddressesClient := network.NewPublicIPAddressesClient(vm.Creds.SubscriptionID)
publicIPAddressesClient.Authorizer = authorizer
_, errc := publicIPAddressesClient.Delete(vm.ResourceGroup, vm.PublicIP, nil)
return <-errc
}
|
go
|
func (vm *VM) deletePublicIP(authorizer autorest.Authorizer) error {
// Delete the Public IP of this VM
publicIPAddressesClient := network.NewPublicIPAddressesClient(vm.Creds.SubscriptionID)
publicIPAddressesClient.Authorizer = authorizer
_, errc := publicIPAddressesClient.Delete(vm.ResourceGroup, vm.PublicIP, nil)
return <-errc
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"deletePublicIP",
"(",
"authorizer",
"autorest",
".",
"Authorizer",
")",
"error",
"{",
"// Delete the Public IP of this VM",
"publicIPAddressesClient",
":=",
"network",
".",
"NewPublicIPAddressesClient",
"(",
"vm",
".",
"Creds",
".",
"SubscriptionID",
")",
"\n",
"publicIPAddressesClient",
".",
"Authorizer",
"=",
"authorizer",
"\n\n",
"_",
",",
"errc",
":=",
"publicIPAddressesClient",
".",
"Delete",
"(",
"vm",
".",
"ResourceGroup",
",",
"vm",
".",
"PublicIP",
",",
"nil",
")",
"\n",
"return",
"<-",
"errc",
"\n",
"}"
] |
// deletePublicIP deletes the reserved Public IP of the given VM from the VM's resource group, returns an error
// if the operation does not succeed.
|
[
"deletePublicIP",
"deletes",
"the",
"reserved",
"Public",
"IP",
"of",
"the",
"given",
"VM",
"from",
"the",
"VM",
"s",
"resource",
"group",
"returns",
"an",
"error",
"if",
"the",
"operation",
"does",
"not",
"succeed",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/arm/util.go#L286-L293
|
146,074 |
apcera/libretto
|
virtualmachine/azure/arm/util.go
|
deleteDeployment
|
func (vm *VM) deleteDeployment(authorizer autorest.Authorizer) error {
// Get the deployments client
deploymentsClient := resources.NewDeploymentsClient(vm.Creds.SubscriptionID)
deploymentsClient.Authorizer = authorizer
// Delete the deployment
_, errc := deploymentsClient.Delete(vm.ResourceGroup, vm.DeploymentName, nil)
return <-errc
}
|
go
|
func (vm *VM) deleteDeployment(authorizer autorest.Authorizer) error {
// Get the deployments client
deploymentsClient := resources.NewDeploymentsClient(vm.Creds.SubscriptionID)
deploymentsClient.Authorizer = authorizer
// Delete the deployment
_, errc := deploymentsClient.Delete(vm.ResourceGroup, vm.DeploymentName, nil)
return <-errc
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"deleteDeployment",
"(",
"authorizer",
"autorest",
".",
"Authorizer",
")",
"error",
"{",
"// Get the deployments client",
"deploymentsClient",
":=",
"resources",
".",
"NewDeploymentsClient",
"(",
"vm",
".",
"Creds",
".",
"SubscriptionID",
")",
"\n",
"deploymentsClient",
".",
"Authorizer",
"=",
"authorizer",
"\n\n",
"// Delete the deployment",
"_",
",",
"errc",
":=",
"deploymentsClient",
".",
"Delete",
"(",
"vm",
".",
"ResourceGroup",
",",
"vm",
".",
"DeploymentName",
",",
"nil",
")",
"\n",
"return",
"<-",
"errc",
"\n",
"}"
] |
// deleteDeployment deletes the deployed azure arm template for this vm.
|
[
"deleteDeployment",
"deletes",
"the",
"deployed",
"azure",
"arm",
"template",
"for",
"this",
"vm",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/azure/arm/util.go#L296-L304
|
146,075 |
apcera/libretto
|
virtualmachine/virtualbox/vm.go
|
GetIPs
|
func (vm *VM) GetIPs() ([]net.IP, error) {
vm.waitUntilReady()
return vm.ips, nil
}
|
go
|
func (vm *VM) GetIPs() ([]net.IP, error) {
vm.waitUntilReady()
return vm.ips, nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"GetIPs",
"(",
")",
"(",
"[",
"]",
"net",
".",
"IP",
",",
"error",
")",
"{",
"vm",
".",
"waitUntilReady",
"(",
")",
"\n\n",
"return",
"vm",
".",
"ips",
",",
"nil",
"\n",
"}"
] |
// GetIPs returns a list of ip addresses associated with the vm through VBox Guest Additions.
|
[
"GetIPs",
"returns",
"a",
"list",
"of",
"ip",
"addresses",
"associated",
"with",
"the",
"vm",
"through",
"VBox",
"Guest",
"Additions",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/vm.go#L168-L172
|
146,076 |
apcera/libretto
|
virtualmachine/virtualbox/vm.go
|
GetState
|
func (vm *VM) GetState() (string, error) {
stdout, err := runner.RunCombinedError("showvminfo", vm.Name)
if err != nil {
return "", lvm.WrapErrors(lvm.ErrVMInfoFailed, err)
}
for _, line := range strings.Split(stdout, "\n") {
// See if this is a NIC
if match := stateRegexp.FindStringSubmatch(line); match != nil {
if match := runningRegexp.FindStringSubmatch(line); match != nil {
return lvm.VMRunning, nil
}
return lvm.VMHalted, nil
}
}
return lvm.VMUnknown, lvm.ErrVMStateFailed
}
|
go
|
func (vm *VM) GetState() (string, error) {
stdout, err := runner.RunCombinedError("showvminfo", vm.Name)
if err != nil {
return "", lvm.WrapErrors(lvm.ErrVMInfoFailed, err)
}
for _, line := range strings.Split(stdout, "\n") {
// See if this is a NIC
if match := stateRegexp.FindStringSubmatch(line); match != nil {
if match := runningRegexp.FindStringSubmatch(line); match != nil {
return lvm.VMRunning, nil
}
return lvm.VMHalted, nil
}
}
return lvm.VMUnknown, lvm.ErrVMStateFailed
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"GetState",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"stdout",
",",
"err",
":=",
"runner",
".",
"RunCombinedError",
"(",
"\"",
"\"",
",",
"vm",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"lvm",
".",
"WrapErrors",
"(",
"lvm",
".",
"ErrVMInfoFailed",
",",
"err",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"line",
":=",
"range",
"strings",
".",
"Split",
"(",
"stdout",
",",
"\"",
"\\n",
"\"",
")",
"{",
"// See if this is a NIC",
"if",
"match",
":=",
"stateRegexp",
".",
"FindStringSubmatch",
"(",
"line",
")",
";",
"match",
"!=",
"nil",
"{",
"if",
"match",
":=",
"runningRegexp",
".",
"FindStringSubmatch",
"(",
"line",
")",
";",
"match",
"!=",
"nil",
"{",
"return",
"lvm",
".",
"VMRunning",
",",
"nil",
"\n",
"}",
"\n",
"return",
"lvm",
".",
"VMHalted",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"lvm",
".",
"VMUnknown",
",",
"lvm",
".",
"ErrVMStateFailed",
"\n",
"}"
] |
// GetState gets the power state of the VM being serviced by this driver.
|
[
"GetState",
"gets",
"the",
"power",
"state",
"of",
"the",
"VM",
"being",
"serviced",
"by",
"this",
"driver",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/vm.go#L175-L190
|
146,077 |
apcera/libretto
|
virtualmachine/virtualbox/vm.go
|
GetInterfaces
|
func (vm *VM) GetInterfaces() ([]NIC, error) {
nics := []NIC{}
stdout, err := runner.RunCombinedError("showvminfo", vm.Name)
if err != nil {
return nil, err
}
for _, line := range strings.Split(stdout, "\n") {
// See if this is a NIC
if match := nicRegexp.FindStringSubmatch(line); match != nil {
var nic NIC
// Get the nic index and the backing
// substr is the nic index with a trailing `:`
substr := strings.Split(match[0], " ")[1]
//Remove the trailing `:` and convert to an integer
idx, err := strconv.Atoi(strings.TrimSuffix(substr, ":"))
if err != nil {
return nil, err
}
nic.Idx = idx
if match := backingRegexp.FindStringSubmatch(line); match != nil {
nic.Backing = Nat
} else if match := disabledRegexp.FindStringSubmatch(line); match != nil {
nic.Backing = Disabled
} else {
nic.Backing = Unsupported
}
nics = append(nics, nic)
}
}
return nics, nil
}
|
go
|
func (vm *VM) GetInterfaces() ([]NIC, error) {
nics := []NIC{}
stdout, err := runner.RunCombinedError("showvminfo", vm.Name)
if err != nil {
return nil, err
}
for _, line := range strings.Split(stdout, "\n") {
// See if this is a NIC
if match := nicRegexp.FindStringSubmatch(line); match != nil {
var nic NIC
// Get the nic index and the backing
// substr is the nic index with a trailing `:`
substr := strings.Split(match[0], " ")[1]
//Remove the trailing `:` and convert to an integer
idx, err := strconv.Atoi(strings.TrimSuffix(substr, ":"))
if err != nil {
return nil, err
}
nic.Idx = idx
if match := backingRegexp.FindStringSubmatch(line); match != nil {
nic.Backing = Nat
} else if match := disabledRegexp.FindStringSubmatch(line); match != nil {
nic.Backing = Disabled
} else {
nic.Backing = Unsupported
}
nics = append(nics, nic)
}
}
return nics, nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"GetInterfaces",
"(",
")",
"(",
"[",
"]",
"NIC",
",",
"error",
")",
"{",
"nics",
":=",
"[",
"]",
"NIC",
"{",
"}",
"\n",
"stdout",
",",
"err",
":=",
"runner",
".",
"RunCombinedError",
"(",
"\"",
"\"",
",",
"vm",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"line",
":=",
"range",
"strings",
".",
"Split",
"(",
"stdout",
",",
"\"",
"\\n",
"\"",
")",
"{",
"// See if this is a NIC",
"if",
"match",
":=",
"nicRegexp",
".",
"FindStringSubmatch",
"(",
"line",
")",
";",
"match",
"!=",
"nil",
"{",
"var",
"nic",
"NIC",
"\n",
"// Get the nic index and the backing",
"// substr is the nic index with a trailing `:`",
"substr",
":=",
"strings",
".",
"Split",
"(",
"match",
"[",
"0",
"]",
",",
"\"",
"\"",
")",
"[",
"1",
"]",
"\n",
"//Remove the trailing `:` and convert to an integer",
"idx",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"strings",
".",
"TrimSuffix",
"(",
"substr",
",",
"\"",
"\"",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"nic",
".",
"Idx",
"=",
"idx",
"\n",
"if",
"match",
":=",
"backingRegexp",
".",
"FindStringSubmatch",
"(",
"line",
")",
";",
"match",
"!=",
"nil",
"{",
"nic",
".",
"Backing",
"=",
"Nat",
"\n",
"}",
"else",
"if",
"match",
":=",
"disabledRegexp",
".",
"FindStringSubmatch",
"(",
"line",
")",
";",
"match",
"!=",
"nil",
"{",
"nic",
".",
"Backing",
"=",
"Disabled",
"\n",
"}",
"else",
"{",
"nic",
".",
"Backing",
"=",
"Unsupported",
"\n",
"}",
"\n",
"nics",
"=",
"append",
"(",
"nics",
",",
"nic",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nics",
",",
"nil",
"\n",
"}"
] |
// GetInterfaces gets all the network cards attached to this VM
|
[
"GetInterfaces",
"gets",
"all",
"the",
"network",
"cards",
"attached",
"to",
"this",
"VM"
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/vm.go#L193-L224
|
146,078 |
apcera/libretto
|
virtualmachine/virtualbox/vm.go
|
Provision
|
func (vm *VM) Provision() error {
var name string
if vm.Name == "" {
name = fmt.Sprintf("vm-%s", uuid.Variant4())
vm.Name = name
}
src := vm.Src
if src == "" {
return lvm.ErrSourceNotSpecified
}
ovaPath, err := filepath.Abs(src)
if err != nil {
return err
}
vm.Src = ovaPath
// See comment on mutex definition for details.
createMutex.Lock()
_, err = runner.RunCombinedError("import", vm.Src, "--vsys", "0", "--vmname", vm.Name)
createMutex.Unlock()
if err != nil {
return err
}
err = vm.configure()
if err != nil {
return err
}
return vm.waitUntilReady()
}
|
go
|
func (vm *VM) Provision() error {
var name string
if vm.Name == "" {
name = fmt.Sprintf("vm-%s", uuid.Variant4())
vm.Name = name
}
src := vm.Src
if src == "" {
return lvm.ErrSourceNotSpecified
}
ovaPath, err := filepath.Abs(src)
if err != nil {
return err
}
vm.Src = ovaPath
// See comment on mutex definition for details.
createMutex.Lock()
_, err = runner.RunCombinedError("import", vm.Src, "--vsys", "0", "--vmname", vm.Name)
createMutex.Unlock()
if err != nil {
return err
}
err = vm.configure()
if err != nil {
return err
}
return vm.waitUntilReady()
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"Provision",
"(",
")",
"error",
"{",
"var",
"name",
"string",
"\n",
"if",
"vm",
".",
"Name",
"==",
"\"",
"\"",
"{",
"name",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"uuid",
".",
"Variant4",
"(",
")",
")",
"\n",
"vm",
".",
"Name",
"=",
"name",
"\n",
"}",
"\n\n",
"src",
":=",
"vm",
".",
"Src",
"\n",
"if",
"src",
"==",
"\"",
"\"",
"{",
"return",
"lvm",
".",
"ErrSourceNotSpecified",
"\n",
"}",
"\n",
"ovaPath",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"src",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"vm",
".",
"Src",
"=",
"ovaPath",
"\n\n",
"// See comment on mutex definition for details.",
"createMutex",
".",
"Lock",
"(",
")",
"\n",
"_",
",",
"err",
"=",
"runner",
".",
"RunCombinedError",
"(",
"\"",
"\"",
",",
"vm",
".",
"Src",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"vm",
".",
"Name",
")",
"\n",
"createMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"err",
"=",
"vm",
".",
"configure",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"vm",
".",
"waitUntilReady",
"(",
")",
"\n",
"}"
] |
// Provision imports the VM and waits until it is booted up.
|
[
"Provision",
"imports",
"the",
"VM",
"and",
"waits",
"until",
"it",
"is",
"booted",
"up",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/vm.go#L227-L258
|
146,079 |
apcera/libretto
|
virtualmachine/virtualbox/vm.go
|
Run
|
func (f vboxRunner) Run(args ...string) (string, string, error) {
var vboxManagePath string
// If vBoxManage is not found in the system path, fall back to the
// hard coded path.
if path, err := exec.LookPath("VBoxManage"); err == nil {
vboxManagePath = path
} else {
vboxManagePath = VBOXMANAGE
}
cmd := exec.Command(vboxManagePath, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout, cmd.Stderr = &stdout, &stderr
err := cmd.Run()
return stdout.String(), stderr.String(), err
}
|
go
|
func (f vboxRunner) Run(args ...string) (string, string, error) {
var vboxManagePath string
// If vBoxManage is not found in the system path, fall back to the
// hard coded path.
if path, err := exec.LookPath("VBoxManage"); err == nil {
vboxManagePath = path
} else {
vboxManagePath = VBOXMANAGE
}
cmd := exec.Command(vboxManagePath, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
var stdout bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout, cmd.Stderr = &stdout, &stderr
err := cmd.Run()
return stdout.String(), stderr.String(), err
}
|
[
"func",
"(",
"f",
"vboxRunner",
")",
"Run",
"(",
"args",
"...",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"var",
"vboxManagePath",
"string",
"\n",
"// If vBoxManage is not found in the system path, fall back to the",
"// hard coded path.",
"if",
"path",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"\"",
"\"",
")",
";",
"err",
"==",
"nil",
"{",
"vboxManagePath",
"=",
"path",
"\n",
"}",
"else",
"{",
"vboxManagePath",
"=",
"VBOXMANAGE",
"\n",
"}",
"\n",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"vboxManagePath",
",",
"args",
"...",
")",
"\n",
"cmd",
".",
"Stdout",
"=",
"os",
".",
"Stdout",
"\n",
"cmd",
".",
"Stderr",
"=",
"os",
".",
"Stderr",
"\n\n",
"var",
"stdout",
"bytes",
".",
"Buffer",
"\n",
"var",
"stderr",
"bytes",
".",
"Buffer",
"\n",
"cmd",
".",
"Stdout",
",",
"cmd",
".",
"Stderr",
"=",
"&",
"stdout",
",",
"&",
"stderr",
"\n",
"err",
":=",
"cmd",
".",
"Run",
"(",
")",
"\n",
"return",
"stdout",
".",
"String",
"(",
")",
",",
"stderr",
".",
"String",
"(",
")",
",",
"err",
"\n",
"}"
] |
// Run runs a VBoxManage command.
|
[
"Run",
"runs",
"a",
"VBoxManage",
"command",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/vm.go#L261-L279
|
146,080 |
apcera/libretto
|
virtualmachine/digitalocean/vm.go
|
Provision
|
func (vm *VM) Provision() error {
b, err := json.Marshal(vm.Config)
if err != nil {
return err
}
client := &http.Client{}
req, err := BuildRequest(vm.APIToken, "POST", apiBaseURL+apiDropletURL, bytes.NewReader(b))
if err != nil {
return err
}
rsp, err := client.Do(req)
if err != nil {
return err
}
defer rsp.Body.Close()
b, err = ioutil.ReadAll(rsp.Body)
if err != nil {
return err
}
if rsp.Status[0] != StatusOk {
return fmt.Errorf("Error: %s: %s", rsp.Status, string(b))
}
// Fill out vm.Droplet with data on new droplet
r := &DropletResponse{}
err = json.Unmarshal(b, r)
if err != nil {
return err
}
vm.Droplet = r.Droplet
return nil
}
|
go
|
func (vm *VM) Provision() error {
b, err := json.Marshal(vm.Config)
if err != nil {
return err
}
client := &http.Client{}
req, err := BuildRequest(vm.APIToken, "POST", apiBaseURL+apiDropletURL, bytes.NewReader(b))
if err != nil {
return err
}
rsp, err := client.Do(req)
if err != nil {
return err
}
defer rsp.Body.Close()
b, err = ioutil.ReadAll(rsp.Body)
if err != nil {
return err
}
if rsp.Status[0] != StatusOk {
return fmt.Errorf("Error: %s: %s", rsp.Status, string(b))
}
// Fill out vm.Droplet with data on new droplet
r := &DropletResponse{}
err = json.Unmarshal(b, r)
if err != nil {
return err
}
vm.Droplet = r.Droplet
return nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"Provision",
"(",
")",
"error",
"{",
"b",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"vm",
".",
"Config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"client",
":=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n",
"req",
",",
"err",
":=",
"BuildRequest",
"(",
"vm",
".",
"APIToken",
",",
"\"",
"\"",
",",
"apiBaseURL",
"+",
"apiDropletURL",
",",
"bytes",
".",
"NewReader",
"(",
"b",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"rsp",
",",
"err",
":=",
"client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"rsp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"b",
",",
"err",
"=",
"ioutil",
".",
"ReadAll",
"(",
"rsp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"rsp",
".",
"Status",
"[",
"0",
"]",
"!=",
"StatusOk",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rsp",
".",
"Status",
",",
"string",
"(",
"b",
")",
")",
"\n",
"}",
"\n\n",
"// Fill out vm.Droplet with data on new droplet",
"r",
":=",
"&",
"DropletResponse",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"vm",
".",
"Droplet",
"=",
"r",
".",
"Droplet",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Provision creates a new VM
|
[
"Provision",
"creates",
"a",
"new",
"VM"
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/digitalocean/vm.go#L165-L197
|
146,081 |
apcera/libretto
|
virtualmachine/digitalocean/vm.go
|
GetIPs
|
func (vm *VM) GetIPs() ([]net.IP, error) {
var ips []net.IP
if err := vm.Update(); err != nil {
return nil, err
}
for _, ip := range vm.Droplet.Networks.V4 {
ips = append(ips, net.ParseIP(ip.IPAddress))
}
for _, ip := range vm.Droplet.Networks.V6 {
ips = append(ips, net.ParseIP(ip.IPAddress))
}
return ips, nil
}
|
go
|
func (vm *VM) GetIPs() ([]net.IP, error) {
var ips []net.IP
if err := vm.Update(); err != nil {
return nil, err
}
for _, ip := range vm.Droplet.Networks.V4 {
ips = append(ips, net.ParseIP(ip.IPAddress))
}
for _, ip := range vm.Droplet.Networks.V6 {
ips = append(ips, net.ParseIP(ip.IPAddress))
}
return ips, nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"GetIPs",
"(",
")",
"(",
"[",
"]",
"net",
".",
"IP",
",",
"error",
")",
"{",
"var",
"ips",
"[",
"]",
"net",
".",
"IP",
"\n",
"if",
"err",
":=",
"vm",
".",
"Update",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"ip",
":=",
"range",
"vm",
".",
"Droplet",
".",
"Networks",
".",
"V4",
"{",
"ips",
"=",
"append",
"(",
"ips",
",",
"net",
".",
"ParseIP",
"(",
"ip",
".",
"IPAddress",
")",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"ip",
":=",
"range",
"vm",
".",
"Droplet",
".",
"Networks",
".",
"V6",
"{",
"ips",
"=",
"append",
"(",
"ips",
",",
"net",
".",
"ParseIP",
"(",
"ip",
".",
"IPAddress",
")",
")",
"\n",
"}",
"\n",
"return",
"ips",
",",
"nil",
"\n",
"}"
] |
// GetIPs returns a list of ip addresses associated with the VM
|
[
"GetIPs",
"returns",
"a",
"list",
"of",
"ip",
"addresses",
"associated",
"with",
"the",
"VM"
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/digitalocean/vm.go#L200-L212
|
146,082 |
apcera/libretto
|
virtualmachine/digitalocean/vm.go
|
GetState
|
func (vm *VM) GetState() (string, error) {
id := fmt.Sprintf("%v", vm.Droplet.ID)
if id == "" {
return "", ErrNoInstanceID
}
client := &http.Client{}
req, err := BuildRequest(vm.APIToken, "GET", apiBaseURL+apiDropletURL+"/"+id, nil)
if err != nil {
return "", err
}
rsp, err := client.Do(req)
if err != nil {
return "", err
}
defer rsp.Body.Close()
b, err := ioutil.ReadAll(rsp.Body)
if err != nil {
return "", err
}
if rsp.StatusCode == StatusNotFound {
return "not_found", nil
}
if rsp.Status[0] != StatusOk {
return "", fmt.Errorf("Error: %s: %s", rsp.Status, string(b))
}
// Fill out vm.Droplet with data on droplet
r := &DropletResponse{}
err = json.Unmarshal(b, r)
if err != nil {
return "", err
}
vm.Droplet = r.Droplet
return vm.Droplet.Status, nil
}
|
go
|
func (vm *VM) GetState() (string, error) {
id := fmt.Sprintf("%v", vm.Droplet.ID)
if id == "" {
return "", ErrNoInstanceID
}
client := &http.Client{}
req, err := BuildRequest(vm.APIToken, "GET", apiBaseURL+apiDropletURL+"/"+id, nil)
if err != nil {
return "", err
}
rsp, err := client.Do(req)
if err != nil {
return "", err
}
defer rsp.Body.Close()
b, err := ioutil.ReadAll(rsp.Body)
if err != nil {
return "", err
}
if rsp.StatusCode == StatusNotFound {
return "not_found", nil
}
if rsp.Status[0] != StatusOk {
return "", fmt.Errorf("Error: %s: %s", rsp.Status, string(b))
}
// Fill out vm.Droplet with data on droplet
r := &DropletResponse{}
err = json.Unmarshal(b, r)
if err != nil {
return "", err
}
vm.Droplet = r.Droplet
return vm.Droplet.Status, nil
}
|
[
"func",
"(",
"vm",
"*",
"VM",
")",
"GetState",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"id",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"vm",
".",
"Droplet",
".",
"ID",
")",
"\n",
"if",
"id",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"ErrNoInstanceID",
"\n",
"}",
"\n\n",
"client",
":=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n",
"req",
",",
"err",
":=",
"BuildRequest",
"(",
"vm",
".",
"APIToken",
",",
"\"",
"\"",
",",
"apiBaseURL",
"+",
"apiDropletURL",
"+",
"\"",
"\"",
"+",
"id",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"rsp",
",",
"err",
":=",
"client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"defer",
"rsp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"rsp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"rsp",
".",
"StatusCode",
"==",
"StatusNotFound",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"if",
"rsp",
".",
"Status",
"[",
"0",
"]",
"!=",
"StatusOk",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"rsp",
".",
"Status",
",",
"string",
"(",
"b",
")",
")",
"\n",
"}",
"\n\n",
"// Fill out vm.Droplet with data on droplet",
"r",
":=",
"&",
"DropletResponse",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"vm",
".",
"Droplet",
"=",
"r",
".",
"Droplet",
"\n",
"return",
"vm",
".",
"Droplet",
".",
"Status",
",",
"nil",
"\n",
"}"
] |
// GetState gets the running state of the VM through the DigitalOcean API
// Returns droplet state if available and 'not_found' if ID could not be located.
|
[
"GetState",
"gets",
"the",
"running",
"state",
"of",
"the",
"VM",
"through",
"the",
"DigitalOcean",
"API",
"Returns",
"droplet",
"state",
"if",
"available",
"and",
"not_found",
"if",
"ID",
"could",
"not",
"be",
"located",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/digitalocean/vm.go#L255-L290
|
146,083 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
findImageAPIVersion
|
func findImageAPIVersion(tokenID string, imageEndpoint string) (int, error) {
// Try to fetch image API version from the imageEndpoint
if strings.HasSuffix(imageEndpoint, "/v1/") {
return 1, nil
}
if strings.HasSuffix(imageEndpoint, "/v2/") {
return 2, nil
}
// Try to fetch version number using the endpoint
versionReq, err := http.NewRequest("GET", imageEndpoint, nil)
if err != nil {
return 0, fmt.Errorf("unable to get image API version")
}
versionReq.Header.Add("X-Auth-Token", tokenID)
versionClient := &http.Client{}
// Send the request to upload the image
resp, err := versionClient.Do(versionReq)
if err != nil {
return 0, fmt.Errorf("failed to send a image API version request")
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
bodyStr := string(body)
if resp.StatusCode != http.StatusMultipleChoices {
return 0, fmt.Errorf("image API version request returned bad response, %s", bodyStr)
}
// Prefer V2 over V1
if match, _ := regexp.MatchString(".*\"id\": \"v2\\.[0-2]+.*\"", bodyStr); match {
return 2, nil
}
if match, _ := regexp.MatchString(".*\"id\": \"v1\\.[0-1]+.*\"", bodyStr); match {
return 1, nil
}
return 0, fmt.Errorf("image API version is not supported")
}
|
go
|
func findImageAPIVersion(tokenID string, imageEndpoint string) (int, error) {
// Try to fetch image API version from the imageEndpoint
if strings.HasSuffix(imageEndpoint, "/v1/") {
return 1, nil
}
if strings.HasSuffix(imageEndpoint, "/v2/") {
return 2, nil
}
// Try to fetch version number using the endpoint
versionReq, err := http.NewRequest("GET", imageEndpoint, nil)
if err != nil {
return 0, fmt.Errorf("unable to get image API version")
}
versionReq.Header.Add("X-Auth-Token", tokenID)
versionClient := &http.Client{}
// Send the request to upload the image
resp, err := versionClient.Do(versionReq)
if err != nil {
return 0, fmt.Errorf("failed to send a image API version request")
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
bodyStr := string(body)
if resp.StatusCode != http.StatusMultipleChoices {
return 0, fmt.Errorf("image API version request returned bad response, %s", bodyStr)
}
// Prefer V2 over V1
if match, _ := regexp.MatchString(".*\"id\": \"v2\\.[0-2]+.*\"", bodyStr); match {
return 2, nil
}
if match, _ := regexp.MatchString(".*\"id\": \"v1\\.[0-1]+.*\"", bodyStr); match {
return 1, nil
}
return 0, fmt.Errorf("image API version is not supported")
}
|
[
"func",
"findImageAPIVersion",
"(",
"tokenID",
"string",
",",
"imageEndpoint",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"// Try to fetch image API version from the imageEndpoint",
"if",
"strings",
".",
"HasSuffix",
"(",
"imageEndpoint",
",",
"\"",
"\"",
")",
"{",
"return",
"1",
",",
"nil",
"\n",
"}",
"\n",
"if",
"strings",
".",
"HasSuffix",
"(",
"imageEndpoint",
",",
"\"",
"\"",
")",
"{",
"return",
"2",
",",
"nil",
"\n",
"}",
"\n\n",
"// Try to fetch version number using the endpoint",
"versionReq",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"imageEndpoint",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"versionReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"tokenID",
")",
"\n",
"versionClient",
":=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n\n",
"// Send the request to upload the image",
"resp",
",",
"err",
":=",
"versionClient",
".",
"Do",
"(",
"versionReq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"body",
",",
"_",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"bodyStr",
":=",
"string",
"(",
"body",
")",
"\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusMultipleChoices",
"{",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"bodyStr",
")",
"\n",
"}",
"\n\n",
"// Prefer V2 over V1",
"if",
"match",
",",
"_",
":=",
"regexp",
".",
"MatchString",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\\",
"\\\"",
"\"",
",",
"bodyStr",
")",
";",
"match",
"{",
"return",
"2",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"match",
",",
"_",
":=",
"regexp",
".",
"MatchString",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\\",
"\\\"",
"\"",
",",
"bodyStr",
")",
";",
"match",
"{",
"return",
"1",
",",
"nil",
"\n",
"}",
"\n",
"return",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// findImageAPIVersion finds the Image API version number. It first checks whether the given
// imageEndpoint has version info. If it is not, then a Get request is sent to imageEndpoint to
// fetch supported APIs. If any V2 api is supported then it returns 2, else If any V1 api is
// supported then it returns 1. Otherwise, it returns an error.
|
[
"findImageAPIVersion",
"finds",
"the",
"Image",
"API",
"version",
"number",
".",
"It",
"first",
"checks",
"whether",
"the",
"given",
"imageEndpoint",
"has",
"version",
"info",
".",
"If",
"it",
"is",
"not",
"then",
"a",
"Get",
"request",
"is",
"sent",
"to",
"imageEndpoint",
"to",
"fetch",
"supported",
"APIs",
".",
"If",
"any",
"V2",
"api",
"is",
"supported",
"then",
"it",
"returns",
"2",
"else",
"If",
"any",
"V1",
"api",
"is",
"supported",
"then",
"it",
"returns",
"1",
".",
"Otherwise",
"it",
"returns",
"an",
"error",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L117-L157
|
146,084 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
reserveImage
|
func reserveImage(tokenID string, imageEndpoint string, imageMetadata ImageMetadata, imageApiVersion int) (string, error) {
// Form the URI to create the image
imagesURI := ""
if imageVersionEncoded(imageEndpoint) {
imagesURI = fmt.Sprintf("%simages", imageEndpoint)
} else {
imagesURI = fmt.Sprintf("%sv%d/images", imageEndpoint, imageApiVersion)
}
// Prepare the request to create the image
var createReq *http.Request
var err error
if imageApiVersion == 1 {
createReq, err = http.NewRequest("POST", imagesURI, nil)
} else {
imageStr, imgErr := json.Marshal(imageMetadata)
if imgErr != nil {
return "", imgErr
}
createReq, err = http.NewRequest("POST", imagesURI, bytes.NewBuffer(imageStr))
}
if err != nil {
return "", err
}
createReq.Header.Add("X-Auth-Token", tokenID)
if imageApiVersion == 1 {
createReq.Header.Add("Content-Type", "application/octet-stream")
createReq.Header.Add("X-Image-Meta-Name", imageMetadata.Name)
createReq.Header.Add("X-Image-Meta-container_format", imageMetadata.ContainerFormat)
createReq.Header.Add("X-Image-Meta-disk_format", imageMetadata.DiskFormat)
createReq.Header.Add("X-Image-Meta-min_disk", strconv.Itoa(imageMetadata.MinDisk))
createReq.Header.Add("X-Image-Meta-min_ram", strconv.Itoa(imageMetadata.MinRAM))
} else {
createReq.Header.Add("Content-Type", "application/json")
}
// Send the request to create the image
httpClient := &http.Client{}
resp, err := httpClient.Do(createReq)
if err != nil {
return "", fmt.Errorf("failed to send a image reserve request")
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
if resp.StatusCode != 201 {
return "", fmt.Errorf("reserve image request returned bad response, %s", string(body))
}
// Parse the result to see if image is created
var dat map[string]interface{}
if err := json.Unmarshal(body, &dat); err != nil {
return "", err
}
if imageApiVersion == 1 {
dat = dat["image"].(map[string]interface{})
}
if dat["status"] != imageQueued {
return "", fmt.Errorf("image has never been created")
}
// Retrieve the image ID from http response block
idFromResponse := dat["id"]
switch idFromResponse.(type) {
case string:
return idFromResponse.(string), nil
default:
return "", fmt.Errorf("unable to parse the upload image response")
}
}
|
go
|
func reserveImage(tokenID string, imageEndpoint string, imageMetadata ImageMetadata, imageApiVersion int) (string, error) {
// Form the URI to create the image
imagesURI := ""
if imageVersionEncoded(imageEndpoint) {
imagesURI = fmt.Sprintf("%simages", imageEndpoint)
} else {
imagesURI = fmt.Sprintf("%sv%d/images", imageEndpoint, imageApiVersion)
}
// Prepare the request to create the image
var createReq *http.Request
var err error
if imageApiVersion == 1 {
createReq, err = http.NewRequest("POST", imagesURI, nil)
} else {
imageStr, imgErr := json.Marshal(imageMetadata)
if imgErr != nil {
return "", imgErr
}
createReq, err = http.NewRequest("POST", imagesURI, bytes.NewBuffer(imageStr))
}
if err != nil {
return "", err
}
createReq.Header.Add("X-Auth-Token", tokenID)
if imageApiVersion == 1 {
createReq.Header.Add("Content-Type", "application/octet-stream")
createReq.Header.Add("X-Image-Meta-Name", imageMetadata.Name)
createReq.Header.Add("X-Image-Meta-container_format", imageMetadata.ContainerFormat)
createReq.Header.Add("X-Image-Meta-disk_format", imageMetadata.DiskFormat)
createReq.Header.Add("X-Image-Meta-min_disk", strconv.Itoa(imageMetadata.MinDisk))
createReq.Header.Add("X-Image-Meta-min_ram", strconv.Itoa(imageMetadata.MinRAM))
} else {
createReq.Header.Add("Content-Type", "application/json")
}
// Send the request to create the image
httpClient := &http.Client{}
resp, err := httpClient.Do(createReq)
if err != nil {
return "", fmt.Errorf("failed to send a image reserve request")
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
if resp.StatusCode != 201 {
return "", fmt.Errorf("reserve image request returned bad response, %s", string(body))
}
// Parse the result to see if image is created
var dat map[string]interface{}
if err := json.Unmarshal(body, &dat); err != nil {
return "", err
}
if imageApiVersion == 1 {
dat = dat["image"].(map[string]interface{})
}
if dat["status"] != imageQueued {
return "", fmt.Errorf("image has never been created")
}
// Retrieve the image ID from http response block
idFromResponse := dat["id"]
switch idFromResponse.(type) {
case string:
return idFromResponse.(string), nil
default:
return "", fmt.Errorf("unable to parse the upload image response")
}
}
|
[
"func",
"reserveImage",
"(",
"tokenID",
"string",
",",
"imageEndpoint",
"string",
",",
"imageMetadata",
"ImageMetadata",
",",
"imageApiVersion",
"int",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Form the URI to create the image",
"imagesURI",
":=",
"\"",
"\"",
"\n",
"if",
"imageVersionEncoded",
"(",
"imageEndpoint",
")",
"{",
"imagesURI",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"imageEndpoint",
")",
"\n",
"}",
"else",
"{",
"imagesURI",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"imageEndpoint",
",",
"imageApiVersion",
")",
"\n",
"}",
"\n\n",
"// Prepare the request to create the image",
"var",
"createReq",
"*",
"http",
".",
"Request",
"\n",
"var",
"err",
"error",
"\n",
"if",
"imageApiVersion",
"==",
"1",
"{",
"createReq",
",",
"err",
"=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"imagesURI",
",",
"nil",
")",
"\n",
"}",
"else",
"{",
"imageStr",
",",
"imgErr",
":=",
"json",
".",
"Marshal",
"(",
"imageMetadata",
")",
"\n",
"if",
"imgErr",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"imgErr",
"\n",
"}",
"\n\n",
"createReq",
",",
"err",
"=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"imagesURI",
",",
"bytes",
".",
"NewBuffer",
"(",
"imageStr",
")",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"createReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"tokenID",
")",
"\n",
"if",
"imageApiVersion",
"==",
"1",
"{",
"createReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"createReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"imageMetadata",
".",
"Name",
")",
"\n",
"createReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"imageMetadata",
".",
"ContainerFormat",
")",
"\n",
"createReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"imageMetadata",
".",
"DiskFormat",
")",
"\n",
"createReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"imageMetadata",
".",
"MinDisk",
")",
")",
"\n",
"createReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"strconv",
".",
"Itoa",
"(",
"imageMetadata",
".",
"MinRAM",
")",
")",
"\n",
"}",
"else",
"{",
"createReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Send the request to create the image",
"httpClient",
":=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n",
"resp",
",",
"err",
":=",
"httpClient",
".",
"Do",
"(",
"createReq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"body",
",",
"_",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"201",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"string",
"(",
"body",
")",
")",
"\n",
"}",
"\n\n",
"// Parse the result to see if image is created",
"var",
"dat",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"dat",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"imageApiVersion",
"==",
"1",
"{",
"dat",
"=",
"dat",
"[",
"\"",
"\"",
"]",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n\n",
"if",
"dat",
"[",
"\"",
"\"",
"]",
"!=",
"imageQueued",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Retrieve the image ID from http response block",
"idFromResponse",
":=",
"dat",
"[",
"\"",
"\"",
"]",
"\n",
"switch",
"idFromResponse",
".",
"(",
"type",
")",
"{",
"case",
"string",
":",
"return",
"idFromResponse",
".",
"(",
"string",
")",
",",
"nil",
"\n",
"default",
":",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}"
] |
// Reserves an Image ID at the specified image endpoint using the information in given imageMetadata
// Returns the reserved Image ID if reservation is successful, otherwise returns an error.
// Requires client's token to reserve the image.
|
[
"Reserves",
"an",
"Image",
"ID",
"at",
"the",
"specified",
"image",
"endpoint",
"using",
"the",
"information",
"in",
"given",
"imageMetadata",
"Returns",
"the",
"reserved",
"Image",
"ID",
"if",
"reservation",
"is",
"successful",
"otherwise",
"returns",
"an",
"error",
".",
"Requires",
"client",
"s",
"token",
"to",
"reserve",
"the",
"image",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L169-L241
|
146,085 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
uploadImage
|
func uploadImage(tokenID string, imageEndpoint string, imageID string, imagePath string, imageApiVersion int) error {
// Read the image file
file, err := os.Open(imagePath)
if err != nil {
return fmt.Errorf("unable to open image file")
}
defer file.Close()
stat, err := file.Stat()
if err != nil {
return fmt.Errorf("unable to get the stats of the image file: %s", err)
}
imageFileSize := stat.Size()
// Prepare the request to upload the image file
imageLocation := ""
if imageVersionEncoded(imageEndpoint) {
imageLocation = fmt.Sprintf("%simages/%s", imageEndpoint, imageID)
} else {
imageLocation = fmt.Sprintf("%sv%d/images/%s", imageEndpoint, imageApiVersion, imageID)
}
if imageApiVersion == 2 {
imageLocation += "/file"
}
uploadReq, err := http.NewRequest("PUT", imageLocation, file)
if err != nil {
return fmt.Errorf("unable to upload image to the openstack")
}
uploadReq.Header.Add("Content-Type", "application/octet-stream")
uploadReq.Header.Add("X-Auth-Token", tokenID)
uploadReq.Header.Add("Content-Length", fmt.Sprintf("%d", imageFileSize))
uploadClient := &http.Client{}
// Send the request to upload the image
resp, err := uploadClient.Do(uploadReq)
if err != nil {
return fmt.Errorf("failed to send a upload image request")
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
if (imageApiVersion == 1 && resp.StatusCode != http.StatusOK) ||
(imageApiVersion == 2 && resp.StatusCode != http.StatusNoContent) {
return fmt.Errorf("upload image request returned bad response, %s", string(body))
}
return nil
}
|
go
|
func uploadImage(tokenID string, imageEndpoint string, imageID string, imagePath string, imageApiVersion int) error {
// Read the image file
file, err := os.Open(imagePath)
if err != nil {
return fmt.Errorf("unable to open image file")
}
defer file.Close()
stat, err := file.Stat()
if err != nil {
return fmt.Errorf("unable to get the stats of the image file: %s", err)
}
imageFileSize := stat.Size()
// Prepare the request to upload the image file
imageLocation := ""
if imageVersionEncoded(imageEndpoint) {
imageLocation = fmt.Sprintf("%simages/%s", imageEndpoint, imageID)
} else {
imageLocation = fmt.Sprintf("%sv%d/images/%s", imageEndpoint, imageApiVersion, imageID)
}
if imageApiVersion == 2 {
imageLocation += "/file"
}
uploadReq, err := http.NewRequest("PUT", imageLocation, file)
if err != nil {
return fmt.Errorf("unable to upload image to the openstack")
}
uploadReq.Header.Add("Content-Type", "application/octet-stream")
uploadReq.Header.Add("X-Auth-Token", tokenID)
uploadReq.Header.Add("Content-Length", fmt.Sprintf("%d", imageFileSize))
uploadClient := &http.Client{}
// Send the request to upload the image
resp, err := uploadClient.Do(uploadReq)
if err != nil {
return fmt.Errorf("failed to send a upload image request")
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
if (imageApiVersion == 1 && resp.StatusCode != http.StatusOK) ||
(imageApiVersion == 2 && resp.StatusCode != http.StatusNoContent) {
return fmt.Errorf("upload image request returned bad response, %s", string(body))
}
return nil
}
|
[
"func",
"uploadImage",
"(",
"tokenID",
"string",
",",
"imageEndpoint",
"string",
",",
"imageID",
"string",
",",
"imagePath",
"string",
",",
"imageApiVersion",
"int",
")",
"error",
"{",
"// Read the image file",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"imagePath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n\n",
"stat",
",",
"err",
":=",
"file",
".",
"Stat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"imageFileSize",
":=",
"stat",
".",
"Size",
"(",
")",
"\n\n",
"// Prepare the request to upload the image file",
"imageLocation",
":=",
"\"",
"\"",
"\n",
"if",
"imageVersionEncoded",
"(",
"imageEndpoint",
")",
"{",
"imageLocation",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"imageEndpoint",
",",
"imageID",
")",
"\n",
"}",
"else",
"{",
"imageLocation",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"imageEndpoint",
",",
"imageApiVersion",
",",
"imageID",
")",
"\n",
"}",
"\n",
"if",
"imageApiVersion",
"==",
"2",
"{",
"imageLocation",
"+=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"uploadReq",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"imageLocation",
",",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"uploadReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"uploadReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"tokenID",
")",
"\n",
"uploadReq",
".",
"Header",
".",
"Add",
"(",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"imageFileSize",
")",
")",
"\n\n",
"uploadClient",
":=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n\n",
"// Send the request to upload the image",
"resp",
",",
"err",
":=",
"uploadClient",
".",
"Do",
"(",
"uploadReq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"body",
",",
"_",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"(",
"imageApiVersion",
"==",
"1",
"&&",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
")",
"||",
"(",
"imageApiVersion",
"==",
"2",
"&&",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusNoContent",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"string",
"(",
"body",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// Uploads the image to an reserved image location at the imageEndpoint using the reserved image ID and imageMetadata.
// Returns nil error if the upload is successful, otherwise returns an error.
// Requires client's token to upload the image.
|
[
"Uploads",
"the",
"image",
"to",
"an",
"reserved",
"image",
"location",
"at",
"the",
"imageEndpoint",
"using",
"the",
"reserved",
"image",
"ID",
"and",
"imageMetadata",
".",
"Returns",
"nil",
"error",
"if",
"the",
"upload",
"is",
"successful",
"otherwise",
"returns",
"an",
"error",
".",
"Requires",
"client",
"s",
"token",
"to",
"upload",
"the",
"image",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L246-L296
|
146,086 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
createImage
|
func createImage(vm *VM) (string, error) {
// Get the openstack provider
provider, err := getProviderClient(vm)
if err != nil {
return "", ErrAuthenticatingClient
}
endpointOpts := gophercloud.EndpointOpts{
Region: vm.Region,
}
// Find the Image Endpoint to upload the image
imageEndpoint, err := findImageEndpoint(provider, endpointOpts)
if err != nil {
return "", err
}
// Find the Image API version number
version, err := findImageAPIVersion(provider.TokenID, imageEndpoint)
if err != nil {
return "", err
}
// Reserve an ImageID at imageEndpoint using the given image metadata
imageID, err := reserveImage(provider.TokenID, imageEndpoint, vm.ImageMetadata, version)
if err != nil {
return "", err
}
// Upload the image to the imageEndpoint with reserved ImageID using the given image path
err = uploadImage(provider.TokenID, imageEndpoint, imageID, vm.ImagePath, version)
if err != nil {
return "", err
}
return imageID, nil
}
|
go
|
func createImage(vm *VM) (string, error) {
// Get the openstack provider
provider, err := getProviderClient(vm)
if err != nil {
return "", ErrAuthenticatingClient
}
endpointOpts := gophercloud.EndpointOpts{
Region: vm.Region,
}
// Find the Image Endpoint to upload the image
imageEndpoint, err := findImageEndpoint(provider, endpointOpts)
if err != nil {
return "", err
}
// Find the Image API version number
version, err := findImageAPIVersion(provider.TokenID, imageEndpoint)
if err != nil {
return "", err
}
// Reserve an ImageID at imageEndpoint using the given image metadata
imageID, err := reserveImage(provider.TokenID, imageEndpoint, vm.ImageMetadata, version)
if err != nil {
return "", err
}
// Upload the image to the imageEndpoint with reserved ImageID using the given image path
err = uploadImage(provider.TokenID, imageEndpoint, imageID, vm.ImagePath, version)
if err != nil {
return "", err
}
return imageID, nil
}
|
[
"func",
"createImage",
"(",
"vm",
"*",
"VM",
")",
"(",
"string",
",",
"error",
")",
"{",
"// Get the openstack provider",
"provider",
",",
"err",
":=",
"getProviderClient",
"(",
"vm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"ErrAuthenticatingClient",
"\n",
"}",
"\n\n",
"endpointOpts",
":=",
"gophercloud",
".",
"EndpointOpts",
"{",
"Region",
":",
"vm",
".",
"Region",
",",
"}",
"\n",
"// Find the Image Endpoint to upload the image",
"imageEndpoint",
",",
"err",
":=",
"findImageEndpoint",
"(",
"provider",
",",
"endpointOpts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// Find the Image API version number",
"version",
",",
"err",
":=",
"findImageAPIVersion",
"(",
"provider",
".",
"TokenID",
",",
"imageEndpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// Reserve an ImageID at imageEndpoint using the given image metadata",
"imageID",
",",
"err",
":=",
"reserveImage",
"(",
"provider",
".",
"TokenID",
",",
"imageEndpoint",
",",
"vm",
".",
"ImageMetadata",
",",
"version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// Upload the image to the imageEndpoint with reserved ImageID using the given image path",
"err",
"=",
"uploadImage",
"(",
"provider",
".",
"TokenID",
",",
"imageEndpoint",
",",
"imageID",
",",
"vm",
".",
"ImagePath",
",",
"version",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"imageID",
",",
"nil",
"\n",
"}"
] |
// Creates an Image based on the given FilePath and returns the UUID of the image
|
[
"Creates",
"an",
"Image",
"based",
"on",
"the",
"given",
"FilePath",
"and",
"returns",
"the",
"UUID",
"of",
"the",
"image"
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L299-L334
|
146,087 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
getServer
|
func getServer(vm *VM) (*servers.Server, error) {
if vm.InstanceID == "" {
// Probably need to call Provision first.
return nil, ErrNoInstanceID
}
client, err := getComputeClient(vm)
if err != nil {
return nil, err
}
status, err := servers.Get(client, vm.InstanceID).Extract()
if status != nil && err != nil {
return nil, fmt.Errorf("failed to retrieve the server for VM")
}
return status, nil
}
|
go
|
func getServer(vm *VM) (*servers.Server, error) {
if vm.InstanceID == "" {
// Probably need to call Provision first.
return nil, ErrNoInstanceID
}
client, err := getComputeClient(vm)
if err != nil {
return nil, err
}
status, err := servers.Get(client, vm.InstanceID).Extract()
if status != nil && err != nil {
return nil, fmt.Errorf("failed to retrieve the server for VM")
}
return status, nil
}
|
[
"func",
"getServer",
"(",
"vm",
"*",
"VM",
")",
"(",
"*",
"servers",
".",
"Server",
",",
"error",
")",
"{",
"if",
"vm",
".",
"InstanceID",
"==",
"\"",
"\"",
"{",
"// Probably need to call Provision first.",
"return",
"nil",
",",
"ErrNoInstanceID",
"\n",
"}",
"\n\n",
"client",
",",
"err",
":=",
"getComputeClient",
"(",
"vm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"status",
",",
"err",
":=",
"servers",
".",
"Get",
"(",
"client",
",",
"vm",
".",
"InstanceID",
")",
".",
"Extract",
"(",
")",
"\n",
"if",
"status",
"!=",
"nil",
"&&",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"status",
",",
"nil",
"\n",
"}"
] |
// getServer returns the Openstack server object for the VM. An error is returned
// if the instance ID is missing, if there was a problem querying Openstack, or if
// there is no instances with the given VM ID.
|
[
"getServer",
"returns",
"the",
"Openstack",
"server",
"object",
"for",
"the",
"VM",
".",
"An",
"error",
"is",
"returned",
"if",
"the",
"instance",
"ID",
"is",
"missing",
"if",
"there",
"was",
"a",
"problem",
"querying",
"Openstack",
"or",
"if",
"there",
"is",
"no",
"instances",
"with",
"the",
"given",
"VM",
"ID",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L339-L356
|
146,088 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
findImageEndpoint
|
func findImageEndpoint(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (string, error) {
eo.ApplyDefaults("image")
url, err := client.EndpointLocator(eo)
if err != nil {
return "", fmt.Errorf("error on locating image endpoint")
}
return url, nil
}
|
go
|
func findImageEndpoint(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (string, error) {
eo.ApplyDefaults("image")
url, err := client.EndpointLocator(eo)
if err != nil {
return "", fmt.Errorf("error on locating image endpoint")
}
return url, nil
}
|
[
"func",
"findImageEndpoint",
"(",
"client",
"*",
"gophercloud",
".",
"ProviderClient",
",",
"eo",
"gophercloud",
".",
"EndpointOpts",
")",
"(",
"string",
",",
"error",
")",
"{",
"eo",
".",
"ApplyDefaults",
"(",
"\"",
"\"",
")",
"\n",
"url",
",",
"err",
":=",
"client",
".",
"EndpointLocator",
"(",
"eo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"url",
",",
"nil",
"\n",
"}"
] |
// Finds the image endpoint in the given openstack Region. Region is passed within gophercloud.EndpointOpts
|
[
"Finds",
"the",
"image",
"endpoint",
"in",
"the",
"given",
"openstack",
"Region",
".",
"Region",
"is",
"passed",
"within",
"gophercloud",
".",
"EndpointOpts"
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L359-L366
|
146,089 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
waitUntil
|
func waitUntil(vm *VM, state string) error {
var curState string
var err error
for i := 0; i < ActionTimeout; i++ {
curState, err = vm.GetState()
if err != nil {
return err
}
if curState == state {
break
}
if curState == lvm.VMError {
return fmt.Errorf("failed to bring the VM to state: %s", state)
}
time.Sleep(1 * time.Second)
}
if curState != state {
return ErrActionTimeout
}
return nil
}
|
go
|
func waitUntil(vm *VM, state string) error {
var curState string
var err error
for i := 0; i < ActionTimeout; i++ {
curState, err = vm.GetState()
if err != nil {
return err
}
if curState == state {
break
}
if curState == lvm.VMError {
return fmt.Errorf("failed to bring the VM to state: %s", state)
}
time.Sleep(1 * time.Second)
}
if curState != state {
return ErrActionTimeout
}
return nil
}
|
[
"func",
"waitUntil",
"(",
"vm",
"*",
"VM",
",",
"state",
"string",
")",
"error",
"{",
"var",
"curState",
"string",
"\n",
"var",
"err",
"error",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"ActionTimeout",
";",
"i",
"++",
"{",
"curState",
",",
"err",
"=",
"vm",
".",
"GetState",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"curState",
"==",
"state",
"{",
"break",
"\n",
"}",
"\n\n",
"if",
"curState",
"==",
"lvm",
".",
"VMError",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"state",
")",
"\n",
"}",
"\n\n",
"time",
".",
"Sleep",
"(",
"1",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"if",
"curState",
"!=",
"state",
"{",
"return",
"ErrActionTimeout",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Waits until the given VM becomes in requested state in given ActionTimeout seconds
|
[
"Waits",
"until",
"the",
"given",
"VM",
"becomes",
"in",
"requested",
"state",
"in",
"given",
"ActionTimeout",
"seconds"
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L369-L392
|
146,090 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
waitUntilSSHReady
|
func waitUntilSSHReady(vm *VM) error {
client, err := vm.GetSSH(ssh.Options{})
if err != nil {
return err
}
return client.WaitForSSH(SSHTimeout)
}
|
go
|
func waitUntilSSHReady(vm *VM) error {
client, err := vm.GetSSH(ssh.Options{})
if err != nil {
return err
}
return client.WaitForSSH(SSHTimeout)
}
|
[
"func",
"waitUntilSSHReady",
"(",
"vm",
"*",
"VM",
")",
"error",
"{",
"client",
",",
"err",
":=",
"vm",
".",
"GetSSH",
"(",
"ssh",
".",
"Options",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"client",
".",
"WaitForSSH",
"(",
"SSHTimeout",
")",
"\n",
"}"
] |
// Waits until the given VM becomes ready. Basically, waits until vm can be sshed.
|
[
"Waits",
"until",
"the",
"given",
"VM",
"becomes",
"ready",
".",
"Basically",
"waits",
"until",
"vm",
"can",
"be",
"sshed",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L395-L401
|
146,091 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
createAndAttachVolume
|
func createAndAttachVolume(vm *VM) error {
if vm.InstanceID == "" {
// Probably need to call Provision first.
return ErrNoInstanceID
}
cClient, err := getComputeClient(vm)
if err != nil {
return fmt.Errorf("compute client is not set for the VM, %s", err)
}
bsClient, err := getBlockStorageClient(vm)
if err != nil {
return err
}
// Creates a new Volume for this VM
volume := vm.Volume
vOpts := volumes.CreateOpts{Size: volume.Size, Name: volume.Name, VolumeType: volume.Type}
vol, err := volumes.Create(bsClient, vOpts).Extract()
if err != nil {
return fmt.Errorf("failed to create a new volume for the VM: %s", err)
}
// Cleanup the volume if something goes wrong
var cleanup = func(err error) error {
if errDeleteVolume := volumes.Delete(bsClient, vol.ID).ExtractErr(); errDeleteVolume != nil {
return fmt.Errorf("%s %s", err, errDeleteVolume)
}
return err
}
// Wait until Volume becomes available
err = waitUntilVolume(bsClient, vol.ID, volumeStateAvailable)
if err != nil {
return cleanup(fmt.Errorf("failed to create a new volume for the VM: %s", err))
}
// Attach the new volume to this VM
vaOpts := volumeattach.CreateOpts{Device: volume.Device, VolumeID: vol.ID}
va, err := volumeattach.Create(cClient, vm.InstanceID, vaOpts).Extract()
if err != nil {
return cleanup(fmt.Errorf("failed to attach the volume to the VM: %s", err))
}
// Wait until Volume is attached to the VM
err = waitUntilVolume(bsClient, vol.ID, volumeStateInUse)
if err != nil {
errVaDelete := volumeattach.Delete(cClient, vm.InstanceID, vol.ID).ExtractErr()
err = fmt.Errorf("%s %s", err, errVaDelete)
return cleanup(fmt.Errorf("failed to attach the volume to the VM: %s", err))
}
vm.Volume.ID = vol.ID
vm.Volume.Device = va.Device
return nil
}
|
go
|
func createAndAttachVolume(vm *VM) error {
if vm.InstanceID == "" {
// Probably need to call Provision first.
return ErrNoInstanceID
}
cClient, err := getComputeClient(vm)
if err != nil {
return fmt.Errorf("compute client is not set for the VM, %s", err)
}
bsClient, err := getBlockStorageClient(vm)
if err != nil {
return err
}
// Creates a new Volume for this VM
volume := vm.Volume
vOpts := volumes.CreateOpts{Size: volume.Size, Name: volume.Name, VolumeType: volume.Type}
vol, err := volumes.Create(bsClient, vOpts).Extract()
if err != nil {
return fmt.Errorf("failed to create a new volume for the VM: %s", err)
}
// Cleanup the volume if something goes wrong
var cleanup = func(err error) error {
if errDeleteVolume := volumes.Delete(bsClient, vol.ID).ExtractErr(); errDeleteVolume != nil {
return fmt.Errorf("%s %s", err, errDeleteVolume)
}
return err
}
// Wait until Volume becomes available
err = waitUntilVolume(bsClient, vol.ID, volumeStateAvailable)
if err != nil {
return cleanup(fmt.Errorf("failed to create a new volume for the VM: %s", err))
}
// Attach the new volume to this VM
vaOpts := volumeattach.CreateOpts{Device: volume.Device, VolumeID: vol.ID}
va, err := volumeattach.Create(cClient, vm.InstanceID, vaOpts).Extract()
if err != nil {
return cleanup(fmt.Errorf("failed to attach the volume to the VM: %s", err))
}
// Wait until Volume is attached to the VM
err = waitUntilVolume(bsClient, vol.ID, volumeStateInUse)
if err != nil {
errVaDelete := volumeattach.Delete(cClient, vm.InstanceID, vol.ID).ExtractErr()
err = fmt.Errorf("%s %s", err, errVaDelete)
return cleanup(fmt.Errorf("failed to attach the volume to the VM: %s", err))
}
vm.Volume.ID = vol.ID
vm.Volume.Device = va.Device
return nil
}
|
[
"func",
"createAndAttachVolume",
"(",
"vm",
"*",
"VM",
")",
"error",
"{",
"if",
"vm",
".",
"InstanceID",
"==",
"\"",
"\"",
"{",
"// Probably need to call Provision first.",
"return",
"ErrNoInstanceID",
"\n",
"}",
"\n\n",
"cClient",
",",
"err",
":=",
"getComputeClient",
"(",
"vm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"bsClient",
",",
"err",
":=",
"getBlockStorageClient",
"(",
"vm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Creates a new Volume for this VM",
"volume",
":=",
"vm",
".",
"Volume",
"\n",
"vOpts",
":=",
"volumes",
".",
"CreateOpts",
"{",
"Size",
":",
"volume",
".",
"Size",
",",
"Name",
":",
"volume",
".",
"Name",
",",
"VolumeType",
":",
"volume",
".",
"Type",
"}",
"\n",
"vol",
",",
"err",
":=",
"volumes",
".",
"Create",
"(",
"bsClient",
",",
"vOpts",
")",
".",
"Extract",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Cleanup the volume if something goes wrong",
"var",
"cleanup",
"=",
"func",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"errDeleteVolume",
":=",
"volumes",
".",
"Delete",
"(",
"bsClient",
",",
"vol",
".",
"ID",
")",
".",
"ExtractErr",
"(",
")",
";",
"errDeleteVolume",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
",",
"errDeleteVolume",
")",
"\n",
"}",
"\n\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Wait until Volume becomes available",
"err",
"=",
"waitUntilVolume",
"(",
"bsClient",
",",
"vol",
".",
"ID",
",",
"volumeStateAvailable",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cleanup",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n\n",
"// Attach the new volume to this VM",
"vaOpts",
":=",
"volumeattach",
".",
"CreateOpts",
"{",
"Device",
":",
"volume",
".",
"Device",
",",
"VolumeID",
":",
"vol",
".",
"ID",
"}",
"\n",
"va",
",",
"err",
":=",
"volumeattach",
".",
"Create",
"(",
"cClient",
",",
"vm",
".",
"InstanceID",
",",
"vaOpts",
")",
".",
"Extract",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cleanup",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n\n",
"// Wait until Volume is attached to the VM",
"err",
"=",
"waitUntilVolume",
"(",
"bsClient",
",",
"vol",
".",
"ID",
",",
"volumeStateInUse",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"errVaDelete",
":=",
"volumeattach",
".",
"Delete",
"(",
"cClient",
",",
"vm",
".",
"InstanceID",
",",
"vol",
".",
"ID",
")",
".",
"ExtractErr",
"(",
")",
"\n",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
",",
"errVaDelete",
")",
"\n",
"return",
"cleanup",
"(",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
")",
"\n",
"}",
"\n\n",
"vm",
".",
"Volume",
".",
"ID",
"=",
"vol",
".",
"ID",
"\n",
"vm",
".",
"Volume",
".",
"Device",
"=",
"va",
".",
"Device",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// createAndAttachVolume creates a new volume with the given volume specs and then attaches this volume to the given VM.
|
[
"createAndAttachVolume",
"creates",
"a",
"new",
"volume",
"with",
"the",
"given",
"volume",
"specs",
"and",
"then",
"attaches",
"this",
"volume",
"to",
"the",
"given",
"VM",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L404-L462
|
146,092 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
deattachAndDeleteVolume
|
func deattachAndDeleteVolume(vm *VM) error {
if vm.InstanceID == "" {
// Probably need to call Provision first.
return ErrNoInstanceID
}
cClient, err := getComputeClient(vm)
if err != nil {
return fmt.Errorf("compute client is not set for the VM, %s", err)
}
bsClient, err := getBlockStorageClient(vm)
if err != nil {
return err
}
// Deattach the volume from the VM
err = volumeattach.Delete(cClient, vm.InstanceID, vm.Volume.ID).ExtractErr()
if err != nil {
return fmt.Errorf("failed to deattach volume from the VM: %s", err)
}
// Wait until Volume is de-attached from the VM
err = waitUntilVolume(bsClient, vm.Volume.ID, volumeStateAvailable)
if err != nil {
return fmt.Errorf("failed to deattach volume from the VM: %s", err)
}
// Delete the volume
err = volumes.Delete(bsClient, vm.Volume.ID).ExtractErr()
if err != nil {
return fmt.Errorf("failed to delete volume: %s", err)
}
// Wait until Volume is deleted
err = waitUntilVolume(bsClient, vm.Volume.ID, volumeStateDeleted)
if err != nil {
return fmt.Errorf("failed to delete volume: %s", err)
}
return nil
}
|
go
|
func deattachAndDeleteVolume(vm *VM) error {
if vm.InstanceID == "" {
// Probably need to call Provision first.
return ErrNoInstanceID
}
cClient, err := getComputeClient(vm)
if err != nil {
return fmt.Errorf("compute client is not set for the VM, %s", err)
}
bsClient, err := getBlockStorageClient(vm)
if err != nil {
return err
}
// Deattach the volume from the VM
err = volumeattach.Delete(cClient, vm.InstanceID, vm.Volume.ID).ExtractErr()
if err != nil {
return fmt.Errorf("failed to deattach volume from the VM: %s", err)
}
// Wait until Volume is de-attached from the VM
err = waitUntilVolume(bsClient, vm.Volume.ID, volumeStateAvailable)
if err != nil {
return fmt.Errorf("failed to deattach volume from the VM: %s", err)
}
// Delete the volume
err = volumes.Delete(bsClient, vm.Volume.ID).ExtractErr()
if err != nil {
return fmt.Errorf("failed to delete volume: %s", err)
}
// Wait until Volume is deleted
err = waitUntilVolume(bsClient, vm.Volume.ID, volumeStateDeleted)
if err != nil {
return fmt.Errorf("failed to delete volume: %s", err)
}
return nil
}
|
[
"func",
"deattachAndDeleteVolume",
"(",
"vm",
"*",
"VM",
")",
"error",
"{",
"if",
"vm",
".",
"InstanceID",
"==",
"\"",
"\"",
"{",
"// Probably need to call Provision first.",
"return",
"ErrNoInstanceID",
"\n",
"}",
"\n\n",
"cClient",
",",
"err",
":=",
"getComputeClient",
"(",
"vm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"bsClient",
",",
"err",
":=",
"getBlockStorageClient",
"(",
"vm",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Deattach the volume from the VM",
"err",
"=",
"volumeattach",
".",
"Delete",
"(",
"cClient",
",",
"vm",
".",
"InstanceID",
",",
"vm",
".",
"Volume",
".",
"ID",
")",
".",
"ExtractErr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Wait until Volume is de-attached from the VM",
"err",
"=",
"waitUntilVolume",
"(",
"bsClient",
",",
"vm",
".",
"Volume",
".",
"ID",
",",
"volumeStateAvailable",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Delete the volume",
"err",
"=",
"volumes",
".",
"Delete",
"(",
"bsClient",
",",
"vm",
".",
"Volume",
".",
"ID",
")",
".",
"ExtractErr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"// Wait until Volume is deleted",
"err",
"=",
"waitUntilVolume",
"(",
"bsClient",
",",
"vm",
".",
"Volume",
".",
"ID",
",",
"volumeStateDeleted",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// deattachAndDeleteVolume deattaches the volume from the given VM and then completely deletes the volume.
|
[
"deattachAndDeleteVolume",
"deattaches",
"the",
"volume",
"from",
"the",
"given",
"VM",
"and",
"then",
"completely",
"deletes",
"the",
"volume",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L465-L506
|
146,093 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
deleteVM
|
func deleteVM(client *gophercloud.ServiceClient, vmID string) error {
err := servers.Delete(client, vmID).ExtractErr()
if err != nil {
return fmt.Errorf("failed to destroy vm %s: %s", vmID, err)
}
return nil
}
|
go
|
func deleteVM(client *gophercloud.ServiceClient, vmID string) error {
err := servers.Delete(client, vmID).ExtractErr()
if err != nil {
return fmt.Errorf("failed to destroy vm %s: %s", vmID, err)
}
return nil
}
|
[
"func",
"deleteVM",
"(",
"client",
"*",
"gophercloud",
".",
"ServiceClient",
",",
"vmID",
"string",
")",
"error",
"{",
"err",
":=",
"servers",
".",
"Delete",
"(",
"client",
",",
"vmID",
")",
".",
"ExtractErr",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"vmID",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// deleteVM deletes the instance.
|
[
"deleteVM",
"deletes",
"the",
"instance",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L509-L515
|
146,094 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
findImageIDByName
|
func findImageIDByName(client *gophercloud.ServiceClient, imageName string) (string, error) {
if imageName == "" {
return "", fmt.Errorf("empty image name")
}
// We have the option of filtering the image list. If we want the full
// collection, leave it as an empty struct
opts := images.ListOpts{Name: imageName}
// Retrieve image list
page, err := images.ListDetail(client, opts).AllPages()
if err != nil {
return "", fmt.Errorf("error on retrieving image pages: %s", err)
}
imageList, err := images.ExtractImages(page)
if err != nil {
return "", fmt.Errorf("error on extracting image list: %s", err)
}
if len(imageList) == 0 {
return "", nil
}
if len(imageList) > 1 {
return "", fmt.Errorf("there exists more than one image with the same name")
}
return imageList[0].ID, err
}
|
go
|
func findImageIDByName(client *gophercloud.ServiceClient, imageName string) (string, error) {
if imageName == "" {
return "", fmt.Errorf("empty image name")
}
// We have the option of filtering the image list. If we want the full
// collection, leave it as an empty struct
opts := images.ListOpts{Name: imageName}
// Retrieve image list
page, err := images.ListDetail(client, opts).AllPages()
if err != nil {
return "", fmt.Errorf("error on retrieving image pages: %s", err)
}
imageList, err := images.ExtractImages(page)
if err != nil {
return "", fmt.Errorf("error on extracting image list: %s", err)
}
if len(imageList) == 0 {
return "", nil
}
if len(imageList) > 1 {
return "", fmt.Errorf("there exists more than one image with the same name")
}
return imageList[0].ID, err
}
|
[
"func",
"findImageIDByName",
"(",
"client",
"*",
"gophercloud",
".",
"ServiceClient",
",",
"imageName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"imageName",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// We have the option of filtering the image list. If we want the full",
"// collection, leave it as an empty struct",
"opts",
":=",
"images",
".",
"ListOpts",
"{",
"Name",
":",
"imageName",
"}",
"\n\n",
"// Retrieve image list",
"page",
",",
"err",
":=",
"images",
".",
"ListDetail",
"(",
"client",
",",
"opts",
")",
".",
"AllPages",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"imageList",
",",
"err",
":=",
"images",
".",
"ExtractImages",
"(",
"page",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"imageList",
")",
"==",
"0",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"imageList",
")",
">",
"1",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"imageList",
"[",
"0",
"]",
".",
"ID",
",",
"err",
"\n",
"}"
] |
// findImageIDByName finds the ImageID for the given imageName, returns an error if there is
// no image or more than one image with the given Image Name.
|
[
"findImageIDByName",
"finds",
"the",
"ImageID",
"for",
"the",
"given",
"imageName",
"returns",
"an",
"error",
"if",
"there",
"is",
"no",
"image",
"or",
"more",
"than",
"one",
"image",
"with",
"the",
"given",
"Image",
"Name",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L519-L548
|
146,095 |
apcera/libretto
|
virtualmachine/openstack/util.go
|
waitUntilVolume
|
func waitUntilVolume(blockStorateClient *gophercloud.ServiceClient, volumeID string, state string) error {
for i := 0; i < VolumeActionTimeout; i++ {
vol, err := volumes.Get(blockStorateClient, volumeID).Extract()
switch {
case vol == nil && state == "nil":
return nil
case vol == nil || err != nil:
return fmt.Errorf("failed on getting volume Status: %s", err)
case vol.Status == state:
return nil
case vol.Status == lvm.VMError || vol.Status == volumeStateErrorDeleting:
return fmt.Errorf("failed to bring the volume to state %s, ended up at state %s", state, vol.Status)
}
time.Sleep(1 * time.Second)
}
return ErrActionTimeout
}
|
go
|
func waitUntilVolume(blockStorateClient *gophercloud.ServiceClient, volumeID string, state string) error {
for i := 0; i < VolumeActionTimeout; i++ {
vol, err := volumes.Get(blockStorateClient, volumeID).Extract()
switch {
case vol == nil && state == "nil":
return nil
case vol == nil || err != nil:
return fmt.Errorf("failed on getting volume Status: %s", err)
case vol.Status == state:
return nil
case vol.Status == lvm.VMError || vol.Status == volumeStateErrorDeleting:
return fmt.Errorf("failed to bring the volume to state %s, ended up at state %s", state, vol.Status)
}
time.Sleep(1 * time.Second)
}
return ErrActionTimeout
}
|
[
"func",
"waitUntilVolume",
"(",
"blockStorateClient",
"*",
"gophercloud",
".",
"ServiceClient",
",",
"volumeID",
"string",
",",
"state",
"string",
")",
"error",
"{",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"VolumeActionTimeout",
";",
"i",
"++",
"{",
"vol",
",",
"err",
":=",
"volumes",
".",
"Get",
"(",
"blockStorateClient",
",",
"volumeID",
")",
".",
"Extract",
"(",
")",
"\n",
"switch",
"{",
"case",
"vol",
"==",
"nil",
"&&",
"state",
"==",
"\"",
"\"",
":",
"return",
"nil",
"\n",
"case",
"vol",
"==",
"nil",
"||",
"err",
"!=",
"nil",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"case",
"vol",
".",
"Status",
"==",
"state",
":",
"return",
"nil",
"\n",
"case",
"vol",
".",
"Status",
"==",
"lvm",
".",
"VMError",
"||",
"vol",
".",
"Status",
"==",
"volumeStateErrorDeleting",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"state",
",",
"vol",
".",
"Status",
")",
"\n",
"}",
"\n",
"time",
".",
"Sleep",
"(",
"1",
"*",
"time",
".",
"Second",
")",
"\n",
"}",
"\n",
"return",
"ErrActionTimeout",
"\n",
"}"
] |
// waitUntilVolume waits until the given volume turns into given state under given VolumeActionTimeout seconds
|
[
"waitUntilVolume",
"waits",
"until",
"the",
"given",
"volume",
"turns",
"into",
"given",
"state",
"under",
"given",
"VolumeActionTimeout",
"seconds"
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/openstack/util.go#L551-L567
|
146,096 |
apcera/libretto
|
virtualmachine/aws/util.go
|
ValidCredentials
|
func ValidCredentials(region string) error {
svc, err := getService(region)
if err != nil {
return fmt.Errorf("failed to get AWS service: %v", err)
}
_, err = svc.DescribeInstances(nil)
awsErr, isAWS := err.(awserr.Error)
if !isAWS {
return err
}
switch awsErr.Code() {
case noCredsCode:
return ErrNoCreds
case noRegionCode:
return ErrNoRegion
}
return nil
}
|
go
|
func ValidCredentials(region string) error {
svc, err := getService(region)
if err != nil {
return fmt.Errorf("failed to get AWS service: %v", err)
}
_, err = svc.DescribeInstances(nil)
awsErr, isAWS := err.(awserr.Error)
if !isAWS {
return err
}
switch awsErr.Code() {
case noCredsCode:
return ErrNoCreds
case noRegionCode:
return ErrNoRegion
}
return nil
}
|
[
"func",
"ValidCredentials",
"(",
"region",
"string",
")",
"error",
"{",
"svc",
",",
"err",
":=",
"getService",
"(",
"region",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"svc",
".",
"DescribeInstances",
"(",
"nil",
")",
"\n",
"awsErr",
",",
"isAWS",
":=",
"err",
".",
"(",
"awserr",
".",
"Error",
")",
"\n",
"if",
"!",
"isAWS",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"switch",
"awsErr",
".",
"Code",
"(",
")",
"{",
"case",
"noCredsCode",
":",
"return",
"ErrNoCreds",
"\n",
"case",
"noRegionCode",
":",
"return",
"ErrNoRegion",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// ValidCredentials sends a dummy request to AWS to check if credentials are
// valid. An error is returned if credentials are missing or region is missing.
|
[
"ValidCredentials",
"sends",
"a",
"dummy",
"request",
"to",
"AWS",
"to",
"check",
"if",
"credentials",
"are",
"valid",
".",
"An",
"error",
"is",
"returned",
"if",
"credentials",
"are",
"missing",
"or",
"region",
"is",
"missing",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/util.go#L36-L56
|
146,097 |
apcera/libretto
|
virtualmachine/aws/util.go
|
UploadKeyPair
|
func UploadKeyPair(publicKey []byte, name string, region string) error {
svc, err := getService(region)
if err != nil {
return fmt.Errorf("failed to get AWS service: %v", err)
}
_, err = svc.ImportKeyPair(&ec2.ImportKeyPairInput{
KeyName: aws.String(name),
PublicKeyMaterial: publicKey,
DryRun: aws.Bool(false),
})
if awsErr, isAWS := err.(awserr.Error); isAWS {
if awsErr.Code() != "InvalidKeyPair.Duplicate" {
return err
}
} else if err != nil {
return err
}
return nil
}
|
go
|
func UploadKeyPair(publicKey []byte, name string, region string) error {
svc, err := getService(region)
if err != nil {
return fmt.Errorf("failed to get AWS service: %v", err)
}
_, err = svc.ImportKeyPair(&ec2.ImportKeyPairInput{
KeyName: aws.String(name),
PublicKeyMaterial: publicKey,
DryRun: aws.Bool(false),
})
if awsErr, isAWS := err.(awserr.Error); isAWS {
if awsErr.Code() != "InvalidKeyPair.Duplicate" {
return err
}
} else if err != nil {
return err
}
return nil
}
|
[
"func",
"UploadKeyPair",
"(",
"publicKey",
"[",
"]",
"byte",
",",
"name",
"string",
",",
"region",
"string",
")",
"error",
"{",
"svc",
",",
"err",
":=",
"getService",
"(",
"region",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"svc",
".",
"ImportKeyPair",
"(",
"&",
"ec2",
".",
"ImportKeyPairInput",
"{",
"KeyName",
":",
"aws",
".",
"String",
"(",
"name",
")",
",",
"PublicKeyMaterial",
":",
"publicKey",
",",
"DryRun",
":",
"aws",
".",
"Bool",
"(",
"false",
")",
",",
"}",
")",
"\n",
"if",
"awsErr",
",",
"isAWS",
":=",
"err",
".",
"(",
"awserr",
".",
"Error",
")",
";",
"isAWS",
"{",
"if",
"awsErr",
".",
"Code",
"(",
")",
"!=",
"\"",
"\"",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// UploadKeyPair uploads the public key to AWS with a given name.
// If the public key already exists, then no error is returned.
|
[
"UploadKeyPair",
"uploads",
"the",
"public",
"key",
"to",
"AWS",
"with",
"a",
"given",
"name",
".",
"If",
"the",
"public",
"key",
"already",
"exists",
"then",
"no",
"error",
"is",
"returned",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/util.go#L247-L267
|
146,098 |
apcera/libretto
|
virtualmachine/aws/util.go
|
DeleteKeyPair
|
func DeleteKeyPair(name string, region string) error {
svc, err := getService(region)
if err != nil {
return fmt.Errorf("failed to get AWS service: %v", err)
}
if name == "" {
return errors.New("Missing key pair name")
}
_, err = svc.DeleteKeyPair(&ec2.DeleteKeyPairInput{
KeyName: aws.String(name),
DryRun: aws.Bool(false),
})
if err != nil {
return fmt.Errorf("Failed to delete key pair: %s", err)
}
return nil
}
|
go
|
func DeleteKeyPair(name string, region string) error {
svc, err := getService(region)
if err != nil {
return fmt.Errorf("failed to get AWS service: %v", err)
}
if name == "" {
return errors.New("Missing key pair name")
}
_, err = svc.DeleteKeyPair(&ec2.DeleteKeyPairInput{
KeyName: aws.String(name),
DryRun: aws.Bool(false),
})
if err != nil {
return fmt.Errorf("Failed to delete key pair: %s", err)
}
return nil
}
|
[
"func",
"DeleteKeyPair",
"(",
"name",
"string",
",",
"region",
"string",
")",
"error",
"{",
"svc",
",",
"err",
":=",
"getService",
"(",
"region",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"name",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"svc",
".",
"DeleteKeyPair",
"(",
"&",
"ec2",
".",
"DeleteKeyPairInput",
"{",
"KeyName",
":",
"aws",
".",
"String",
"(",
"name",
")",
",",
"DryRun",
":",
"aws",
".",
"Bool",
"(",
"false",
")",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// DeleteKeyPair deletes the given key pair from the given region.
|
[
"DeleteKeyPair",
"deletes",
"the",
"given",
"key",
"pair",
"from",
"the",
"given",
"region",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/aws/util.go#L270-L289
|
146,099 |
apcera/libretto
|
virtualmachine/virtualbox/util.go
|
getBridgedDeviceKV
|
func getBridgedDeviceKV(keyname, propname string) ([]ifKeyValue, error) {
kvs := []ifKeyValue{}
if keyname == "" || propname == "" {
return kvs, nil
}
stdout, _, err := runner.Run("list", "bridgedifs")
if err != nil {
return kvs, err
}
matches := networkRegexp.FindAllString(stdout, -1)
if len(matches) < 1 {
return kvs, nil
}
keyid := strings.TrimSuffix(keyname, ":") + ":"
propid := strings.TrimSuffix(propname, ":") + ":"
// Each match is a device
for _, device := range matches {
var kv ifKeyValue
// Find the record that contains keyname and retrieve propname value.
for _, line := range strings.Split(device, "\n") {
if strings.Contains(line, keyid) {
kv.k = strings.TrimSpace(strings.TrimPrefix(line, keyid))
} else if strings.Contains(line, propid) {
kv.v = strings.TrimSpace(strings.TrimPrefix(line, propid))
}
if kv.k != "" && kv.v != "" {
kvs = append(kvs, kv)
break
}
}
}
return kvs, nil
}
|
go
|
func getBridgedDeviceKV(keyname, propname string) ([]ifKeyValue, error) {
kvs := []ifKeyValue{}
if keyname == "" || propname == "" {
return kvs, nil
}
stdout, _, err := runner.Run("list", "bridgedifs")
if err != nil {
return kvs, err
}
matches := networkRegexp.FindAllString(stdout, -1)
if len(matches) < 1 {
return kvs, nil
}
keyid := strings.TrimSuffix(keyname, ":") + ":"
propid := strings.TrimSuffix(propname, ":") + ":"
// Each match is a device
for _, device := range matches {
var kv ifKeyValue
// Find the record that contains keyname and retrieve propname value.
for _, line := range strings.Split(device, "\n") {
if strings.Contains(line, keyid) {
kv.k = strings.TrimSpace(strings.TrimPrefix(line, keyid))
} else if strings.Contains(line, propid) {
kv.v = strings.TrimSpace(strings.TrimPrefix(line, propid))
}
if kv.k != "" && kv.v != "" {
kvs = append(kvs, kv)
break
}
}
}
return kvs, nil
}
|
[
"func",
"getBridgedDeviceKV",
"(",
"keyname",
",",
"propname",
"string",
")",
"(",
"[",
"]",
"ifKeyValue",
",",
"error",
")",
"{",
"kvs",
":=",
"[",
"]",
"ifKeyValue",
"{",
"}",
"\n",
"if",
"keyname",
"==",
"\"",
"\"",
"||",
"propname",
"==",
"\"",
"\"",
"{",
"return",
"kvs",
",",
"nil",
"\n",
"}",
"\n\n",
"stdout",
",",
"_",
",",
"err",
":=",
"runner",
".",
"Run",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"kvs",
",",
"err",
"\n",
"}",
"\n",
"matches",
":=",
"networkRegexp",
".",
"FindAllString",
"(",
"stdout",
",",
"-",
"1",
")",
"\n",
"if",
"len",
"(",
"matches",
")",
"<",
"1",
"{",
"return",
"kvs",
",",
"nil",
"\n",
"}",
"\n\n",
"keyid",
":=",
"strings",
".",
"TrimSuffix",
"(",
"keyname",
",",
"\"",
"\"",
")",
"+",
"\"",
"\"",
"\n",
"propid",
":=",
"strings",
".",
"TrimSuffix",
"(",
"propname",
",",
"\"",
"\"",
")",
"+",
"\"",
"\"",
"\n",
"// Each match is a device",
"for",
"_",
",",
"device",
":=",
"range",
"matches",
"{",
"var",
"kv",
"ifKeyValue",
"\n",
"// Find the record that contains keyname and retrieve propname value.",
"for",
"_",
",",
"line",
":=",
"range",
"strings",
".",
"Split",
"(",
"device",
",",
"\"",
"\\n",
"\"",
")",
"{",
"if",
"strings",
".",
"Contains",
"(",
"line",
",",
"keyid",
")",
"{",
"kv",
".",
"k",
"=",
"strings",
".",
"TrimSpace",
"(",
"strings",
".",
"TrimPrefix",
"(",
"line",
",",
"keyid",
")",
")",
"\n",
"}",
"else",
"if",
"strings",
".",
"Contains",
"(",
"line",
",",
"propid",
")",
"{",
"kv",
".",
"v",
"=",
"strings",
".",
"TrimSpace",
"(",
"strings",
".",
"TrimPrefix",
"(",
"line",
",",
"propid",
")",
")",
"\n",
"}",
"\n",
"if",
"kv",
".",
"k",
"!=",
"\"",
"\"",
"&&",
"kv",
".",
"v",
"!=",
"\"",
"\"",
"{",
"kvs",
"=",
"append",
"(",
"kvs",
",",
"kv",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"kvs",
",",
"nil",
"\n",
"}"
] |
// getBridgedDeviceKV returns a list of key and value pairs of chosen key and value names
// from VBoxManage list bridgedifs results.
|
[
"getBridgedDeviceKV",
"returns",
"a",
"list",
"of",
"key",
"and",
"value",
"pairs",
"of",
"chosen",
"key",
"and",
"value",
"names",
"from",
"VBoxManage",
"list",
"bridgedifs",
"results",
"."
] |
3178799fbb1e39c74b02e3ecf46330b3ef0ed486
|
https://github.com/apcera/libretto/blob/3178799fbb1e39c74b02e3ecf46330b3ef0ed486/virtualmachine/virtualbox/util.go#L21-L55
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.