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
sequencelengths 21
1.41k
| docstring
stringlengths 6
2.61k
| docstring_tokens
sequencelengths 3
215
| sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
5,000 | juju/juju | worker/peergrouper/desired.go | updateAddresses | func (p *peerGroupChanges) updateAddresses() error {
var err error
if p.info.haSpace == "" {
err = p.updateAddressesFromInternal()
} else {
err = p.updateAddressesFromSpace()
}
return errors.Annotate(err, "updating member addresses")
} | go | func (p *peerGroupChanges) updateAddresses() error {
var err error
if p.info.haSpace == "" {
err = p.updateAddressesFromInternal()
} else {
err = p.updateAddressesFromSpace()
}
return errors.Annotate(err, "updating member addresses")
} | [
"func",
"(",
"p",
"*",
"peerGroupChanges",
")",
"updateAddresses",
"(",
")",
"error",
"{",
"var",
"err",
"error",
"\n",
"if",
"p",
".",
"info",
".",
"haSpace",
"==",
"\"",
"\"",
"{",
"err",
"=",
"p",
".",
"updateAddressesFromInternal",
"(",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"p",
".",
"updateAddressesFromSpace",
"(",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // updateAddresses updates the member addresses in the new replica-set, using
// the HA space if one is configured. | [
"updateAddresses",
"updates",
"the",
"member",
"addresses",
"in",
"the",
"new",
"replica",
"-",
"set",
"using",
"the",
"HA",
"space",
"if",
"one",
"is",
"configured",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/peergrouper/desired.go#L478-L486 |
5,001 | juju/juju | worker/peergrouper/desired.go | updateAddressesFromSpace | func (p *peerGroupChanges) updateAddressesFromSpace() error {
space := p.info.haSpace
var noAddresses []string
for _, id := range p.sortedMemberIds() {
m := p.info.machines[id]
addr, err := m.SelectMongoAddressFromSpace(p.info.mongoPort, space)
if err != nil {
if errors.IsNotFound(err) {
noAddresses = append(noAddresses, id)
msg := fmt.Sprintf("no addresses in configured juju-ha-space %q", space)
if err := m.stm.SetStatus(getStatusInfo(msg)); err != nil {
return errors.Trace(err)
}
continue
}
return errors.Trace(err)
}
if addr != p.desired.members[id].Address {
p.desired.members[id].Address = addr
p.desired.isChanged = true
}
}
if len(noAddresses) > 0 {
ids := strings.Join(noAddresses, ", ")
return fmt.Errorf("no usable Mongo addresses found in configured juju-ha-space %q for machines: %s", space, ids)
}
return nil
} | go | func (p *peerGroupChanges) updateAddressesFromSpace() error {
space := p.info.haSpace
var noAddresses []string
for _, id := range p.sortedMemberIds() {
m := p.info.machines[id]
addr, err := m.SelectMongoAddressFromSpace(p.info.mongoPort, space)
if err != nil {
if errors.IsNotFound(err) {
noAddresses = append(noAddresses, id)
msg := fmt.Sprintf("no addresses in configured juju-ha-space %q", space)
if err := m.stm.SetStatus(getStatusInfo(msg)); err != nil {
return errors.Trace(err)
}
continue
}
return errors.Trace(err)
}
if addr != p.desired.members[id].Address {
p.desired.members[id].Address = addr
p.desired.isChanged = true
}
}
if len(noAddresses) > 0 {
ids := strings.Join(noAddresses, ", ")
return fmt.Errorf("no usable Mongo addresses found in configured juju-ha-space %q for machines: %s", space, ids)
}
return nil
} | [
"func",
"(",
"p",
"*",
"peerGroupChanges",
")",
"updateAddressesFromSpace",
"(",
")",
"error",
"{",
"space",
":=",
"p",
".",
"info",
".",
"haSpace",
"\n",
"var",
"noAddresses",
"[",
"]",
"string",
"\n\n",
"for",
"_",
",",
"id",
":=",
"range",
"p",
".",
"sortedMemberIds",
"(",
")",
"{",
"m",
":=",
"p",
".",
"info",
".",
"machines",
"[",
"id",
"]",
"\n",
"addr",
",",
"err",
":=",
"m",
".",
"SelectMongoAddressFromSpace",
"(",
"p",
".",
"info",
".",
"mongoPort",
",",
"space",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"noAddresses",
"=",
"append",
"(",
"noAddresses",
",",
"id",
")",
"\n",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"space",
")",
"\n",
"if",
"err",
":=",
"m",
".",
"stm",
".",
"SetStatus",
"(",
"getStatusInfo",
"(",
"msg",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"addr",
"!=",
"p",
".",
"desired",
".",
"members",
"[",
"id",
"]",
".",
"Address",
"{",
"p",
".",
"desired",
".",
"members",
"[",
"id",
"]",
".",
"Address",
"=",
"addr",
"\n",
"p",
".",
"desired",
".",
"isChanged",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"noAddresses",
")",
">",
"0",
"{",
"ids",
":=",
"strings",
".",
"Join",
"(",
"noAddresses",
",",
"\"",
"\"",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"space",
",",
"ids",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // updateAddressesFromSpace updates the member addresses based on the
// configured HA space.
// If no addresses are available for any of the machines, then such machines
// have their status set and are included in the detail of the returned error. | [
"updateAddressesFromSpace",
"updates",
"the",
"member",
"addresses",
"based",
"on",
"the",
"configured",
"HA",
"space",
".",
"If",
"no",
"addresses",
"are",
"available",
"for",
"any",
"of",
"the",
"machines",
"then",
"such",
"machines",
"have",
"their",
"status",
"set",
"and",
"are",
"included",
"in",
"the",
"detail",
"of",
"the",
"returned",
"error",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/peergrouper/desired.go#L573-L602 |
5,002 | juju/juju | worker/peergrouper/desired.go | sortedMemberIds | func (p *peerGroupChanges) sortedMemberIds() []string {
memberIds := make([]string, 0, len(p.desired.members))
for id := range p.desired.members {
memberIds = append(memberIds, id)
}
sortAsInts(memberIds)
return memberIds
} | go | func (p *peerGroupChanges) sortedMemberIds() []string {
memberIds := make([]string, 0, len(p.desired.members))
for id := range p.desired.members {
memberIds = append(memberIds, id)
}
sortAsInts(memberIds)
return memberIds
} | [
"func",
"(",
"p",
"*",
"peerGroupChanges",
")",
"sortedMemberIds",
"(",
")",
"[",
"]",
"string",
"{",
"memberIds",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"p",
".",
"desired",
".",
"members",
")",
")",
"\n",
"for",
"id",
":=",
"range",
"p",
".",
"desired",
".",
"members",
"{",
"memberIds",
"=",
"append",
"(",
"memberIds",
",",
"id",
")",
"\n",
"}",
"\n",
"sortAsInts",
"(",
"memberIds",
")",
"\n",
"return",
"memberIds",
"\n",
"}"
] | // sortedMemberIds returns the list of p.desired.members in integer-sorted order | [
"sortedMemberIds",
"returns",
"the",
"list",
"of",
"p",
".",
"desired",
".",
"members",
"in",
"integer",
"-",
"sorted",
"order"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/peergrouper/desired.go#L605-L612 |
5,003 | juju/juju | environs/filestorage/filestorage.go | NewFileStorageReader | func NewFileStorageReader(path string) (reader storage.StorageReader, err error) {
var p string
if p, err = utils.NormalizePath(path); err != nil {
return nil, err
}
if p, err = filepath.Abs(p); err != nil {
return nil, err
}
fi, err := os.Stat(p)
if err != nil {
return nil, err
}
if !fi.Mode().IsDir() {
return nil, fmt.Errorf("specified source path is not a directory: %s", path)
}
return &fileStorageReader{p}, nil
} | go | func NewFileStorageReader(path string) (reader storage.StorageReader, err error) {
var p string
if p, err = utils.NormalizePath(path); err != nil {
return nil, err
}
if p, err = filepath.Abs(p); err != nil {
return nil, err
}
fi, err := os.Stat(p)
if err != nil {
return nil, err
}
if !fi.Mode().IsDir() {
return nil, fmt.Errorf("specified source path is not a directory: %s", path)
}
return &fileStorageReader{p}, nil
} | [
"func",
"NewFileStorageReader",
"(",
"path",
"string",
")",
"(",
"reader",
"storage",
".",
"StorageReader",
",",
"err",
"error",
")",
"{",
"var",
"p",
"string",
"\n",
"if",
"p",
",",
"err",
"=",
"utils",
".",
"NormalizePath",
"(",
"path",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"p",
",",
"err",
"=",
"filepath",
".",
"Abs",
"(",
"p",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"p",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"fi",
".",
"Mode",
"(",
")",
".",
"IsDir",
"(",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"}",
"\n",
"return",
"&",
"fileStorageReader",
"{",
"p",
"}",
",",
"nil",
"\n",
"}"
] | // NewFileStorageReader returns a new storage reader for
// a directory inside the local file system. | [
"NewFileStorageReader",
"returns",
"a",
"new",
"storage",
"reader",
"for",
"a",
"directory",
"inside",
"the",
"local",
"file",
"system",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/filestorage/filestorage.go#L29-L45 |
5,004 | juju/juju | environs/filestorage/filestorage.go | Get | func (f *fileStorageReader) Get(name string) (io.ReadCloser, error) {
if isInternalPath(name) {
return nil, &os.PathError{
Op: "Get",
Path: name,
Err: os.ErrNotExist,
}
}
filename := f.fullPath(name)
fi, err := os.Stat(filename)
if err != nil {
if os.IsNotExist(err) {
err = errors.NewNotFound(err, "")
}
return nil, err
} else if fi.IsDir() {
return nil, errors.NotFoundf("no such file with name %q", name)
}
file, err := os.Open(filename)
if err != nil {
return nil, err
}
return file, nil
} | go | func (f *fileStorageReader) Get(name string) (io.ReadCloser, error) {
if isInternalPath(name) {
return nil, &os.PathError{
Op: "Get",
Path: name,
Err: os.ErrNotExist,
}
}
filename := f.fullPath(name)
fi, err := os.Stat(filename)
if err != nil {
if os.IsNotExist(err) {
err = errors.NewNotFound(err, "")
}
return nil, err
} else if fi.IsDir() {
return nil, errors.NotFoundf("no such file with name %q", name)
}
file, err := os.Open(filename)
if err != nil {
return nil, err
}
return file, nil
} | [
"func",
"(",
"f",
"*",
"fileStorageReader",
")",
"Get",
"(",
"name",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"if",
"isInternalPath",
"(",
"name",
")",
"{",
"return",
"nil",
",",
"&",
"os",
".",
"PathError",
"{",
"Op",
":",
"\"",
"\"",
",",
"Path",
":",
"name",
",",
"Err",
":",
"os",
".",
"ErrNotExist",
",",
"}",
"\n",
"}",
"\n",
"filename",
":=",
"f",
".",
"fullPath",
"(",
"name",
")",
"\n",
"fi",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"err",
"=",
"errors",
".",
"NewNotFound",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"fi",
".",
"IsDir",
"(",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"NotFoundf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"file",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"file",
",",
"nil",
"\n",
"}"
] | // Get implements storage.StorageReader.Get. | [
"Get",
"implements",
"storage",
".",
"StorageReader",
".",
"Get",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/filestorage/filestorage.go#L52-L75 |
5,005 | juju/juju | environs/filestorage/filestorage.go | List | func (f *fileStorageReader) List(prefix string) ([]string, error) {
var names []string
if isInternalPath(prefix) {
return names, nil
}
prefix = filepath.Join(f.path, prefix)
dir := filepath.Dir(prefix)
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && strings.HasPrefix(path, prefix) {
names = append(names, path[len(f.path)+1:])
}
return nil
})
if err != nil && !os.IsNotExist(err) {
return nil, err
}
sort.Strings(names)
return names, nil
} | go | func (f *fileStorageReader) List(prefix string) ([]string, error) {
var names []string
if isInternalPath(prefix) {
return names, nil
}
prefix = filepath.Join(f.path, prefix)
dir := filepath.Dir(prefix)
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() && strings.HasPrefix(path, prefix) {
names = append(names, path[len(f.path)+1:])
}
return nil
})
if err != nil && !os.IsNotExist(err) {
return nil, err
}
sort.Strings(names)
return names, nil
} | [
"func",
"(",
"f",
"*",
"fileStorageReader",
")",
"List",
"(",
"prefix",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"names",
"[",
"]",
"string",
"\n",
"if",
"isInternalPath",
"(",
"prefix",
")",
"{",
"return",
"names",
",",
"nil",
"\n",
"}",
"\n",
"prefix",
"=",
"filepath",
".",
"Join",
"(",
"f",
".",
"path",
",",
"prefix",
")",
"\n",
"dir",
":=",
"filepath",
".",
"Dir",
"(",
"prefix",
")",
"\n",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"dir",
",",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"info",
".",
"IsDir",
"(",
")",
"&&",
"strings",
".",
"HasPrefix",
"(",
"path",
",",
"prefix",
")",
"{",
"names",
"=",
"append",
"(",
"names",
",",
"path",
"[",
"len",
"(",
"f",
".",
"path",
")",
"+",
"1",
":",
"]",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"names",
")",
"\n",
"return",
"names",
",",
"nil",
"\n",
"}"
] | // List implements storage.StorageReader.List. | [
"List",
"implements",
"storage",
".",
"StorageReader",
".",
"List",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/filestorage/filestorage.go#L87-L108 |
5,006 | juju/juju | environs/filestorage/filestorage.go | URL | func (f *fileStorageReader) URL(name string) (string, error) {
return utils.MakeFileURL(filepath.Join(f.path, name)), nil
} | go | func (f *fileStorageReader) URL(name string) (string, error) {
return utils.MakeFileURL(filepath.Join(f.path, name)), nil
} | [
"func",
"(",
"f",
"*",
"fileStorageReader",
")",
"URL",
"(",
"name",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"return",
"utils",
".",
"MakeFileURL",
"(",
"filepath",
".",
"Join",
"(",
"f",
".",
"path",
",",
"name",
")",
")",
",",
"nil",
"\n",
"}"
] | // URL implements storage.StorageReader.URL. | [
"URL",
"implements",
"storage",
".",
"StorageReader",
".",
"URL",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/filestorage/filestorage.go#L111-L113 |
5,007 | juju/juju | apiserver/facades/controller/modelupgrader/modelupgrader.go | NewFacade | func NewFacade(
backend Backend,
pool Pool,
providers ProviderRegistry,
entityWatcher EntityWatcher,
statusSetter StatusSetter,
auth facade.Authorizer,
) (*Facade, error) {
if !auth.AuthController() {
return nil, common.ErrPerm
}
return &Facade{
backend: backend,
pool: pool,
providers: providers,
entityWatcher: entityWatcher,
statusSetter: statusSetter,
}, nil
} | go | func NewFacade(
backend Backend,
pool Pool,
providers ProviderRegistry,
entityWatcher EntityWatcher,
statusSetter StatusSetter,
auth facade.Authorizer,
) (*Facade, error) {
if !auth.AuthController() {
return nil, common.ErrPerm
}
return &Facade{
backend: backend,
pool: pool,
providers: providers,
entityWatcher: entityWatcher,
statusSetter: statusSetter,
}, nil
} | [
"func",
"NewFacade",
"(",
"backend",
"Backend",
",",
"pool",
"Pool",
",",
"providers",
"ProviderRegistry",
",",
"entityWatcher",
"EntityWatcher",
",",
"statusSetter",
"StatusSetter",
",",
"auth",
"facade",
".",
"Authorizer",
",",
")",
"(",
"*",
"Facade",
",",
"error",
")",
"{",
"if",
"!",
"auth",
".",
"AuthController",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"return",
"&",
"Facade",
"{",
"backend",
":",
"backend",
",",
"pool",
":",
"pool",
",",
"providers",
":",
"providers",
",",
"entityWatcher",
":",
"entityWatcher",
",",
"statusSetter",
":",
"statusSetter",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewFacade returns a new Facade using the given Backend and Authorizer. | [
"NewFacade",
"returns",
"a",
"new",
"Facade",
"using",
"the",
"given",
"Backend",
"and",
"Authorizer",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/modelupgrader/modelupgrader.go#L62-L80 |
5,008 | juju/juju | apiserver/facades/controller/modelupgrader/modelupgrader.go | ModelTargetEnvironVersion | func (f *Facade) ModelTargetEnvironVersion(args params.Entities) (params.IntResults, error) {
result := params.IntResults{
Results: make([]params.IntResult, len(args.Entities)),
}
for i, arg := range args.Entities {
v, err := f.modelTargetEnvironVersion(arg)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
result.Results[i].Result = v
}
return result, nil
} | go | func (f *Facade) ModelTargetEnvironVersion(args params.Entities) (params.IntResults, error) {
result := params.IntResults{
Results: make([]params.IntResult, len(args.Entities)),
}
for i, arg := range args.Entities {
v, err := f.modelTargetEnvironVersion(arg)
if err != nil {
result.Results[i].Error = common.ServerError(err)
continue
}
result.Results[i].Result = v
}
return result, nil
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"ModelTargetEnvironVersion",
"(",
"args",
"params",
".",
"Entities",
")",
"(",
"params",
".",
"IntResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"IntResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"IntResult",
",",
"len",
"(",
"args",
".",
"Entities",
")",
")",
",",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Entities",
"{",
"v",
",",
"err",
":=",
"f",
".",
"modelTargetEnvironVersion",
"(",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Result",
"=",
"v",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // ModelTargetEnvironVersion returns the target version of the environ
// corresponding to each specified model. The target version is the
// environ provider's version. | [
"ModelTargetEnvironVersion",
"returns",
"the",
"target",
"version",
"of",
"the",
"environ",
"corresponding",
"to",
"each",
"specified",
"model",
".",
"The",
"target",
"version",
"is",
"the",
"environ",
"provider",
"s",
"version",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/modelupgrader/modelupgrader.go#L115-L128 |
5,009 | juju/juju | apiserver/facades/controller/modelupgrader/modelupgrader.go | SetModelEnvironVersion | func (f *Facade) SetModelEnvironVersion(args params.SetModelEnvironVersions) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Models)),
}
for i, arg := range args.Models {
err := f.setModelEnvironVersion(arg)
if err != nil {
result.Results[i].Error = common.ServerError(err)
}
}
return result, nil
} | go | func (f *Facade) SetModelEnvironVersion(args params.SetModelEnvironVersions) (params.ErrorResults, error) {
result := params.ErrorResults{
Results: make([]params.ErrorResult, len(args.Models)),
}
for i, arg := range args.Models {
err := f.setModelEnvironVersion(arg)
if err != nil {
result.Results[i].Error = common.ServerError(err)
}
}
return result, nil
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"SetModelEnvironVersion",
"(",
"args",
"params",
".",
"SetModelEnvironVersions",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"ErrorResults",
"{",
"Results",
":",
"make",
"(",
"[",
"]",
"params",
".",
"ErrorResult",
",",
"len",
"(",
"args",
".",
"Models",
")",
")",
",",
"}",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
".",
"Models",
"{",
"err",
":=",
"f",
".",
"setModelEnvironVersion",
"(",
"arg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"result",
".",
"Results",
"[",
"i",
"]",
".",
"Error",
"=",
"common",
".",
"ServerError",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // SetModelEnvironVersion sets the current version of the environ corresponding
// to each specified model. | [
"SetModelEnvironVersion",
"sets",
"the",
"current",
"version",
"of",
"the",
"environ",
"corresponding",
"to",
"each",
"specified",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/modelupgrader/modelupgrader.go#L153-L164 |
5,010 | juju/juju | apiserver/facades/controller/modelupgrader/modelupgrader.go | SetModelStatus | func (f *Facade) SetModelStatus(args params.SetStatus) (params.ErrorResults, error) {
return f.statusSetter.SetStatus(args)
} | go | func (f *Facade) SetModelStatus(args params.SetStatus) (params.ErrorResults, error) {
return f.statusSetter.SetStatus(args)
} | [
"func",
"(",
"f",
"*",
"Facade",
")",
"SetModelStatus",
"(",
"args",
"params",
".",
"SetStatus",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"return",
"f",
".",
"statusSetter",
".",
"SetStatus",
"(",
"args",
")",
"\n",
"}"
] | // SetModelStatus sets the status of each given model. | [
"SetModelStatus",
"sets",
"the",
"status",
"of",
"each",
"given",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/modelupgrader/modelupgrader.go#L189-L191 |
5,011 | juju/juju | cmd/juju/metricsdebug/metrics.go | Init | func (c *MetricsCommand) Init(args []string) error {
if !c.All && len(args) == 0 {
return errors.New("you need to specify at least one unit or application")
} else if c.All && len(args) > 0 {
return errors.New("cannot use --all with additional entities")
}
c.Tags = make([]string, len(args))
for i, arg := range args {
if names.IsValidUnit(arg) {
c.Tags[i] = names.NewUnitTag(arg).String()
} else if names.IsValidApplication(arg) {
c.Tags[i] = names.NewApplicationTag(arg).String()
} else {
return errors.Errorf("%q is not a valid unit or application", args[0])
}
}
return nil
} | go | func (c *MetricsCommand) Init(args []string) error {
if !c.All && len(args) == 0 {
return errors.New("you need to specify at least one unit or application")
} else if c.All && len(args) > 0 {
return errors.New("cannot use --all with additional entities")
}
c.Tags = make([]string, len(args))
for i, arg := range args {
if names.IsValidUnit(arg) {
c.Tags[i] = names.NewUnitTag(arg).String()
} else if names.IsValidApplication(arg) {
c.Tags[i] = names.NewApplicationTag(arg).String()
} else {
return errors.Errorf("%q is not a valid unit or application", args[0])
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"MetricsCommand",
")",
"Init",
"(",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"!",
"c",
".",
"All",
"&&",
"len",
"(",
"args",
")",
"==",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"c",
".",
"All",
"&&",
"len",
"(",
"args",
")",
">",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"c",
".",
"Tags",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"args",
")",
")",
"\n",
"for",
"i",
",",
"arg",
":=",
"range",
"args",
"{",
"if",
"names",
".",
"IsValidUnit",
"(",
"arg",
")",
"{",
"c",
".",
"Tags",
"[",
"i",
"]",
"=",
"names",
".",
"NewUnitTag",
"(",
"arg",
")",
".",
"String",
"(",
")",
"\n",
"}",
"else",
"if",
"names",
".",
"IsValidApplication",
"(",
"arg",
")",
"{",
"c",
".",
"Tags",
"[",
"i",
"]",
"=",
"names",
".",
"NewApplicationTag",
"(",
"arg",
")",
".",
"String",
"(",
")",
"\n",
"}",
"else",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"args",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Init reads and verifies the cli arguments for the MetricsCommand | [
"Init",
"reads",
"and",
"verifies",
"the",
"cli",
"arguments",
"for",
"the",
"MetricsCommand"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/metricsdebug/metrics.go#L54-L71 |
5,012 | juju/juju | cmd/juju/metricsdebug/metrics.go | Less | func (slice metricSlice) Less(i, j int) bool {
if slice[i].Metric == slice[j].Metric {
return renderLabels(slice[i].Labels) < renderLabels(slice[j].Labels)
}
return slice[i].Metric < slice[j].Metric
} | go | func (slice metricSlice) Less(i, j int) bool {
if slice[i].Metric == slice[j].Metric {
return renderLabels(slice[i].Labels) < renderLabels(slice[j].Labels)
}
return slice[i].Metric < slice[j].Metric
} | [
"func",
"(",
"slice",
"metricSlice",
")",
"Less",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"if",
"slice",
"[",
"i",
"]",
".",
"Metric",
"==",
"slice",
"[",
"j",
"]",
".",
"Metric",
"{",
"return",
"renderLabels",
"(",
"slice",
"[",
"i",
"]",
".",
"Labels",
")",
"<",
"renderLabels",
"(",
"slice",
"[",
"j",
"]",
".",
"Labels",
")",
"\n",
"}",
"\n",
"return",
"slice",
"[",
"i",
"]",
".",
"Metric",
"<",
"slice",
"[",
"j",
"]",
".",
"Metric",
"\n",
"}"
] | // Less implements the sort.Interface. | [
"Less",
"implements",
"the",
"sort",
".",
"Interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/metricsdebug/metrics.go#L105-L110 |
5,013 | juju/juju | cmd/juju/metricsdebug/metrics.go | Swap | func (slice metricSlice) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
} | go | func (slice metricSlice) Swap(i, j int) {
slice[i], slice[j] = slice[j], slice[i]
} | [
"func",
"(",
"slice",
"metricSlice",
")",
"Swap",
"(",
"i",
",",
"j",
"int",
")",
"{",
"slice",
"[",
"i",
"]",
",",
"slice",
"[",
"j",
"]",
"=",
"slice",
"[",
"j",
"]",
",",
"slice",
"[",
"i",
"]",
"\n",
"}"
] | // Swap implements the sort.Interface. | [
"Swap",
"implements",
"the",
"sort",
".",
"Interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/metricsdebug/metrics.go#L113-L115 |
5,014 | juju/juju | cmd/juju/metricsdebug/metrics.go | formatTabular | func formatTabular(writer io.Writer, value interface{}) error {
metrics, ok := value.([]metric)
if !ok {
return errors.Errorf("expected value of type %T, got %T", metrics, value)
}
table := uitable.New()
table.MaxColWidth = 50
table.Wrap = true
for _, col := range []int{1, 2, 3, 4} {
table.RightAlign(col)
}
table.AddRow("UNIT", "TIMESTAMP", "METRIC", "VALUE", "LABELS")
for _, m := range metrics {
table.AddRow(m.Unit, m.Timestamp.Format(time.RFC3339), m.Metric, m.Value, renderLabels(m.Labels))
}
_, err := fmt.Fprint(writer, table.String())
return errors.Trace(err)
} | go | func formatTabular(writer io.Writer, value interface{}) error {
metrics, ok := value.([]metric)
if !ok {
return errors.Errorf("expected value of type %T, got %T", metrics, value)
}
table := uitable.New()
table.MaxColWidth = 50
table.Wrap = true
for _, col := range []int{1, 2, 3, 4} {
table.RightAlign(col)
}
table.AddRow("UNIT", "TIMESTAMP", "METRIC", "VALUE", "LABELS")
for _, m := range metrics {
table.AddRow(m.Unit, m.Timestamp.Format(time.RFC3339), m.Metric, m.Value, renderLabels(m.Labels))
}
_, err := fmt.Fprint(writer, table.String())
return errors.Trace(err)
} | [
"func",
"formatTabular",
"(",
"writer",
"io",
".",
"Writer",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"metrics",
",",
"ok",
":=",
"value",
".",
"(",
"[",
"]",
"metric",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"metrics",
",",
"value",
")",
"\n",
"}",
"\n",
"table",
":=",
"uitable",
".",
"New",
"(",
")",
"\n",
"table",
".",
"MaxColWidth",
"=",
"50",
"\n",
"table",
".",
"Wrap",
"=",
"true",
"\n",
"for",
"_",
",",
"col",
":=",
"range",
"[",
"]",
"int",
"{",
"1",
",",
"2",
",",
"3",
",",
"4",
"}",
"{",
"table",
".",
"RightAlign",
"(",
"col",
")",
"\n",
"}",
"\n",
"table",
".",
"AddRow",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"m",
":=",
"range",
"metrics",
"{",
"table",
".",
"AddRow",
"(",
"m",
".",
"Unit",
",",
"m",
".",
"Timestamp",
".",
"Format",
"(",
"time",
".",
"RFC3339",
")",
",",
"m",
".",
"Metric",
",",
"m",
".",
"Value",
",",
"renderLabels",
"(",
"m",
".",
"Labels",
")",
")",
"\n",
"}",
"\n",
"_",
",",
"err",
":=",
"fmt",
".",
"Fprint",
"(",
"writer",
",",
"table",
".",
"String",
"(",
")",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // formatTabular returns a tabular view of collected metrics. | [
"formatTabular",
"returns",
"a",
"tabular",
"view",
"of",
"collected",
"metrics",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/metricsdebug/metrics.go#L161-L178 |
5,015 | juju/juju | api/instancepoller/machine.go | Status | func (m *Machine) Status() (params.StatusResult, error) {
var results params.StatusResults
args := params.Entities{Entities: []params.Entity{
{Tag: m.tag.String()},
}}
err := m.facade.FacadeCall("Status", args, &results)
if err != nil {
return params.StatusResult{}, errors.Trace(err)
}
if len(results.Results) != 1 {
err := errors.Errorf("expected 1 result, got %d", len(results.Results))
return params.StatusResult{}, err
}
result := results.Results[0]
if result.Error != nil {
return params.StatusResult{}, result.Error
}
return result, nil
} | go | func (m *Machine) Status() (params.StatusResult, error) {
var results params.StatusResults
args := params.Entities{Entities: []params.Entity{
{Tag: m.tag.String()},
}}
err := m.facade.FacadeCall("Status", args, &results)
if err != nil {
return params.StatusResult{}, errors.Trace(err)
}
if len(results.Results) != 1 {
err := errors.Errorf("expected 1 result, got %d", len(results.Results))
return params.StatusResult{}, err
}
result := results.Results[0]
if result.Error != nil {
return params.StatusResult{}, result.Error
}
return result, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"Status",
"(",
")",
"(",
"params",
".",
"StatusResult",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"StatusResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
"}",
",",
"}",
"}",
"\n",
"err",
":=",
"m",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"StatusResult",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"err",
":=",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"return",
"params",
".",
"StatusResult",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"params",
".",
"StatusResult",
"{",
"}",
",",
"result",
".",
"Error",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Status returns the machine status. | [
"Status",
"returns",
"the",
"machine",
"status",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/instancepoller/machine.go#L58-L76 |
5,016 | juju/juju | api/instancepoller/machine.go | IsManual | func (m *Machine) IsManual() (bool, error) {
var results params.BoolResults
args := params.Entities{Entities: []params.Entity{
{Tag: m.tag.String()},
}}
err := m.facade.FacadeCall("AreManuallyProvisioned", args, &results)
if err != nil {
return false, errors.Trace(err)
}
if len(results.Results) != 1 {
err := errors.Errorf("expected 1 result, got %d", len(results.Results))
return false, err
}
result := results.Results[0]
if result.Error != nil {
return false, result.Error
}
return result.Result, nil
} | go | func (m *Machine) IsManual() (bool, error) {
var results params.BoolResults
args := params.Entities{Entities: []params.Entity{
{Tag: m.tag.String()},
}}
err := m.facade.FacadeCall("AreManuallyProvisioned", args, &results)
if err != nil {
return false, errors.Trace(err)
}
if len(results.Results) != 1 {
err := errors.Errorf("expected 1 result, got %d", len(results.Results))
return false, err
}
result := results.Results[0]
if result.Error != nil {
return false, result.Error
}
return result.Result, nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"IsManual",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"BoolResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
"}",
",",
"}",
"}",
"\n",
"err",
":=",
"m",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"err",
":=",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"false",
",",
"result",
".",
"Error",
"\n",
"}",
"\n",
"return",
"result",
".",
"Result",
",",
"nil",
"\n",
"}"
] | // IsManual returns whether the machine is manually provisioned. | [
"IsManual",
"returns",
"whether",
"the",
"machine",
"is",
"manually",
"provisioned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/instancepoller/machine.go#L79-L97 |
5,017 | juju/juju | api/instancepoller/machine.go | ProviderAddresses | func (m *Machine) ProviderAddresses() ([]network.Address, error) {
var results params.MachineAddressesResults
args := params.Entities{Entities: []params.Entity{
{Tag: m.tag.String()},
}}
err := m.facade.FacadeCall("ProviderAddresses", args, &results)
if err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != 1 {
err := errors.Errorf("expected 1 result, got %d", len(results.Results))
return nil, err
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
return params.NetworkAddresses(result.Addresses...), nil
} | go | func (m *Machine) ProviderAddresses() ([]network.Address, error) {
var results params.MachineAddressesResults
args := params.Entities{Entities: []params.Entity{
{Tag: m.tag.String()},
}}
err := m.facade.FacadeCall("ProviderAddresses", args, &results)
if err != nil {
return nil, errors.Trace(err)
}
if len(results.Results) != 1 {
err := errors.Errorf("expected 1 result, got %d", len(results.Results))
return nil, err
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
return params.NetworkAddresses(result.Addresses...), nil
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"ProviderAddresses",
"(",
")",
"(",
"[",
"]",
"network",
".",
"Address",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"MachineAddressesResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
"}",
",",
"}",
"}",
"\n",
"err",
":=",
"m",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"err",
":=",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"result",
".",
"Error",
"!=",
"nil",
"{",
"return",
"nil",
",",
"result",
".",
"Error",
"\n",
"}",
"\n",
"return",
"params",
".",
"NetworkAddresses",
"(",
"result",
".",
"Addresses",
"...",
")",
",",
"nil",
"\n",
"}"
] | // ProviderAddresses returns all addresses of the machine known to the
// cloud provider. | [
"ProviderAddresses",
"returns",
"all",
"addresses",
"of",
"the",
"machine",
"known",
"to",
"the",
"cloud",
"provider",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/instancepoller/machine.go#L156-L174 |
5,018 | juju/juju | api/instancepoller/machine.go | SetProviderAddresses | func (m *Machine) SetProviderAddresses(addrs ...network.Address) error {
var result params.ErrorResults
args := params.SetMachinesAddresses{
MachineAddresses: []params.MachineAddresses{{
Tag: m.tag.String(),
Addresses: params.FromNetworkAddresses(addrs...),
}}}
err := m.facade.FacadeCall("SetProviderAddresses", args, &result)
if err != nil {
return err
}
return result.OneError()
} | go | func (m *Machine) SetProviderAddresses(addrs ...network.Address) error {
var result params.ErrorResults
args := params.SetMachinesAddresses{
MachineAddresses: []params.MachineAddresses{{
Tag: m.tag.String(),
Addresses: params.FromNetworkAddresses(addrs...),
}}}
err := m.facade.FacadeCall("SetProviderAddresses", args, &result)
if err != nil {
return err
}
return result.OneError()
} | [
"func",
"(",
"m",
"*",
"Machine",
")",
"SetProviderAddresses",
"(",
"addrs",
"...",
"network",
".",
"Address",
")",
"error",
"{",
"var",
"result",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"SetMachinesAddresses",
"{",
"MachineAddresses",
":",
"[",
"]",
"params",
".",
"MachineAddresses",
"{",
"{",
"Tag",
":",
"m",
".",
"tag",
".",
"String",
"(",
")",
",",
"Addresses",
":",
"params",
".",
"FromNetworkAddresses",
"(",
"addrs",
"...",
")",
",",
"}",
"}",
"}",
"\n",
"err",
":=",
"m",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"result",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"result",
".",
"OneError",
"(",
")",
"\n",
"}"
] | // SetProviderAddresses sets the cached provider addresses for the
// machine. | [
"SetProviderAddresses",
"sets",
"the",
"cached",
"provider",
"addresses",
"for",
"the",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/instancepoller/machine.go#L178-L190 |
5,019 | juju/juju | state/bakerystorage.go | NewBakeryStorage | func (st *State) NewBakeryStorage() (bakerystorage.ExpirableStorage, error) {
return bakerystorage.New(bakerystorage.Config{
GetCollection: func() (mongo.Collection, func()) {
return st.db().GetCollection(bakeryStorageItemsC)
},
GetStorage: func(rootKeys *mgostorage.RootKeys, coll mongo.Collection, expireAfter time.Duration) bakery.Storage {
return rootKeys.NewStorage(coll.Writeable().Underlying(), mgostorage.Policy{
ExpiryDuration: expireAfter,
})
},
})
} | go | func (st *State) NewBakeryStorage() (bakerystorage.ExpirableStorage, error) {
return bakerystorage.New(bakerystorage.Config{
GetCollection: func() (mongo.Collection, func()) {
return st.db().GetCollection(bakeryStorageItemsC)
},
GetStorage: func(rootKeys *mgostorage.RootKeys, coll mongo.Collection, expireAfter time.Duration) bakery.Storage {
return rootKeys.NewStorage(coll.Writeable().Underlying(), mgostorage.Policy{
ExpiryDuration: expireAfter,
})
},
})
} | [
"func",
"(",
"st",
"*",
"State",
")",
"NewBakeryStorage",
"(",
")",
"(",
"bakerystorage",
".",
"ExpirableStorage",
",",
"error",
")",
"{",
"return",
"bakerystorage",
".",
"New",
"(",
"bakerystorage",
".",
"Config",
"{",
"GetCollection",
":",
"func",
"(",
")",
"(",
"mongo",
".",
"Collection",
",",
"func",
"(",
")",
")",
"{",
"return",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"bakeryStorageItemsC",
")",
"\n",
"}",
",",
"GetStorage",
":",
"func",
"(",
"rootKeys",
"*",
"mgostorage",
".",
"RootKeys",
",",
"coll",
"mongo",
".",
"Collection",
",",
"expireAfter",
"time",
".",
"Duration",
")",
"bakery",
".",
"Storage",
"{",
"return",
"rootKeys",
".",
"NewStorage",
"(",
"coll",
".",
"Writeable",
"(",
")",
".",
"Underlying",
"(",
")",
",",
"mgostorage",
".",
"Policy",
"{",
"ExpiryDuration",
":",
"expireAfter",
",",
"}",
")",
"\n",
"}",
",",
"}",
")",
"\n",
"}"
] | // NewBakeryStorage returns a new bakery.Storage. By default, items
// added to the store are retained until deleted explicitly. The
// store's ExpireAfter method can be called to derive a new store that
// will expire items at the specified time. | [
"NewBakeryStorage",
"returns",
"a",
"new",
"bakery",
".",
"Storage",
".",
"By",
"default",
"items",
"added",
"to",
"the",
"store",
"are",
"retained",
"until",
"deleted",
"explicitly",
".",
"The",
"store",
"s",
"ExpireAfter",
"method",
"can",
"be",
"called",
"to",
"derive",
"a",
"new",
"store",
"that",
"will",
"expire",
"items",
"at",
"the",
"specified",
"time",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/bakerystorage.go#L20-L31 |
5,020 | juju/juju | apiserver/facades/controller/caasoperatorprovisioner/provisioner.go | NewStateCAASOperatorProvisionerAPI | func NewStateCAASOperatorProvisionerAPI(ctx facade.Context) (*API, error) {
authorizer := ctx.Auth()
resources := ctx.Resources()
broker, err := stateenvirons.GetNewCAASBrokerFunc(caas.New)(ctx.State())
if err != nil {
return nil, errors.Annotate(err, "getting caas client")
}
registry := stateenvirons.NewStorageProviderRegistry(broker)
pm := poolmanager.New(state.NewStateSettings(ctx.State()), registry)
return NewCAASOperatorProvisionerAPI(resources, authorizer, stateShim{ctx.State()}, pm, registry)
} | go | func NewStateCAASOperatorProvisionerAPI(ctx facade.Context) (*API, error) {
authorizer := ctx.Auth()
resources := ctx.Resources()
broker, err := stateenvirons.GetNewCAASBrokerFunc(caas.New)(ctx.State())
if err != nil {
return nil, errors.Annotate(err, "getting caas client")
}
registry := stateenvirons.NewStorageProviderRegistry(broker)
pm := poolmanager.New(state.NewStateSettings(ctx.State()), registry)
return NewCAASOperatorProvisionerAPI(resources, authorizer, stateShim{ctx.State()}, pm, registry)
} | [
"func",
"NewStateCAASOperatorProvisionerAPI",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"*",
"API",
",",
"error",
")",
"{",
"authorizer",
":=",
"ctx",
".",
"Auth",
"(",
")",
"\n",
"resources",
":=",
"ctx",
".",
"Resources",
"(",
")",
"\n\n",
"broker",
",",
"err",
":=",
"stateenvirons",
".",
"GetNewCAASBrokerFunc",
"(",
"caas",
".",
"New",
")",
"(",
"ctx",
".",
"State",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"registry",
":=",
"stateenvirons",
".",
"NewStorageProviderRegistry",
"(",
"broker",
")",
"\n",
"pm",
":=",
"poolmanager",
".",
"New",
"(",
"state",
".",
"NewStateSettings",
"(",
"ctx",
".",
"State",
"(",
")",
")",
",",
"registry",
")",
"\n\n",
"return",
"NewCAASOperatorProvisionerAPI",
"(",
"resources",
",",
"authorizer",
",",
"stateShim",
"{",
"ctx",
".",
"State",
"(",
")",
"}",
",",
"pm",
",",
"registry",
")",
"\n",
"}"
] | // NewStateCAASOperatorProvisionerAPI provides the signature required for facade registration. | [
"NewStateCAASOperatorProvisionerAPI",
"provides",
"the",
"signature",
"required",
"for",
"facade",
"registration",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/caasoperatorprovisioner/provisioner.go#L41-L54 |
5,021 | juju/juju | apiserver/facades/controller/caasoperatorprovisioner/provisioner.go | NewCAASOperatorProvisionerAPI | func NewCAASOperatorProvisionerAPI(
resources facade.Resources,
authorizer facade.Authorizer,
st CAASOperatorProvisionerState,
storagePoolManager poolmanager.PoolManager,
registry storage.ProviderRegistry,
) (*API, error) {
if !authorizer.AuthController() {
return nil, common.ErrPerm
}
return &API{
PasswordChanger: common.NewPasswordChanger(st, common.AuthFuncForTagKind(names.ApplicationTagKind)),
LifeGetter: common.NewLifeGetter(st, common.AuthFuncForTagKind(names.ApplicationTagKind)),
APIAddresser: common.NewAPIAddresser(st, resources),
auth: authorizer,
resources: resources,
state: st,
storagePoolManager: storagePoolManager,
registry: registry,
}, nil
} | go | func NewCAASOperatorProvisionerAPI(
resources facade.Resources,
authorizer facade.Authorizer,
st CAASOperatorProvisionerState,
storagePoolManager poolmanager.PoolManager,
registry storage.ProviderRegistry,
) (*API, error) {
if !authorizer.AuthController() {
return nil, common.ErrPerm
}
return &API{
PasswordChanger: common.NewPasswordChanger(st, common.AuthFuncForTagKind(names.ApplicationTagKind)),
LifeGetter: common.NewLifeGetter(st, common.AuthFuncForTagKind(names.ApplicationTagKind)),
APIAddresser: common.NewAPIAddresser(st, resources),
auth: authorizer,
resources: resources,
state: st,
storagePoolManager: storagePoolManager,
registry: registry,
}, nil
} | [
"func",
"NewCAASOperatorProvisionerAPI",
"(",
"resources",
"facade",
".",
"Resources",
",",
"authorizer",
"facade",
".",
"Authorizer",
",",
"st",
"CAASOperatorProvisionerState",
",",
"storagePoolManager",
"poolmanager",
".",
"PoolManager",
",",
"registry",
"storage",
".",
"ProviderRegistry",
",",
")",
"(",
"*",
"API",
",",
"error",
")",
"{",
"if",
"!",
"authorizer",
".",
"AuthController",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n",
"return",
"&",
"API",
"{",
"PasswordChanger",
":",
"common",
".",
"NewPasswordChanger",
"(",
"st",
",",
"common",
".",
"AuthFuncForTagKind",
"(",
"names",
".",
"ApplicationTagKind",
")",
")",
",",
"LifeGetter",
":",
"common",
".",
"NewLifeGetter",
"(",
"st",
",",
"common",
".",
"AuthFuncForTagKind",
"(",
"names",
".",
"ApplicationTagKind",
")",
")",
",",
"APIAddresser",
":",
"common",
".",
"NewAPIAddresser",
"(",
"st",
",",
"resources",
")",
",",
"auth",
":",
"authorizer",
",",
"resources",
":",
"resources",
",",
"state",
":",
"st",
",",
"storagePoolManager",
":",
"storagePoolManager",
",",
"registry",
":",
"registry",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewCAASOperatorProvisionerAPI returns a new CAAS operator provisioner API facade. | [
"NewCAASOperatorProvisionerAPI",
"returns",
"a",
"new",
"CAAS",
"operator",
"provisioner",
"API",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/caasoperatorprovisioner/provisioner.go#L57-L77 |
5,022 | juju/juju | apiserver/facades/controller/caasoperatorprovisioner/provisioner.go | CharmStorageParams | func CharmStorageParams(
controllerUUID string,
storageClassName string,
modelCfg *config.Config,
poolName string,
poolManager poolmanager.PoolManager,
registry storage.ProviderRegistry,
) (params.KubernetesFilesystemParams, error) {
// The defaults here are for operator storage.
// Workload storage will override these elsewhere.
var size uint64 = 1024
tags := tags.ResourceTags(
names.NewModelTag(modelCfg.UUID()),
names.NewControllerTag(controllerUUID),
modelCfg,
)
result := params.KubernetesFilesystemParams{
StorageName: "charm",
Size: size,
Provider: string(provider.K8s_ProviderType),
Tags: tags,
Attributes: make(map[string]interface{}),
}
// The storage key value from the model config might correspond
// to a storage pool, unless there's been a specific storage pool
// requested.
// First, blank out the fallback pool name used in previous
// versions of Juju.
if poolName == string(provider.K8s_ProviderType) {
poolName = ""
}
maybePoolName := poolName
if maybePoolName == "" {
maybePoolName = storageClassName
}
providerType, attrs, err := poolStorageProvider(poolManager, registry, maybePoolName)
if err != nil && (!errors.IsNotFound(err) || poolName != "") {
return params.KubernetesFilesystemParams{}, errors.Trace(err)
}
if err == nil {
result.Provider = string(providerType)
if len(attrs) > 0 {
result.Attributes = attrs
}
}
if _, ok := result.Attributes[provider.StorageClass]; !ok && result.Provider == string(provider.K8s_ProviderType) {
result.Attributes[provider.StorageClass] = storageClassName
}
return result, nil
} | go | func CharmStorageParams(
controllerUUID string,
storageClassName string,
modelCfg *config.Config,
poolName string,
poolManager poolmanager.PoolManager,
registry storage.ProviderRegistry,
) (params.KubernetesFilesystemParams, error) {
// The defaults here are for operator storage.
// Workload storage will override these elsewhere.
var size uint64 = 1024
tags := tags.ResourceTags(
names.NewModelTag(modelCfg.UUID()),
names.NewControllerTag(controllerUUID),
modelCfg,
)
result := params.KubernetesFilesystemParams{
StorageName: "charm",
Size: size,
Provider: string(provider.K8s_ProviderType),
Tags: tags,
Attributes: make(map[string]interface{}),
}
// The storage key value from the model config might correspond
// to a storage pool, unless there's been a specific storage pool
// requested.
// First, blank out the fallback pool name used in previous
// versions of Juju.
if poolName == string(provider.K8s_ProviderType) {
poolName = ""
}
maybePoolName := poolName
if maybePoolName == "" {
maybePoolName = storageClassName
}
providerType, attrs, err := poolStorageProvider(poolManager, registry, maybePoolName)
if err != nil && (!errors.IsNotFound(err) || poolName != "") {
return params.KubernetesFilesystemParams{}, errors.Trace(err)
}
if err == nil {
result.Provider = string(providerType)
if len(attrs) > 0 {
result.Attributes = attrs
}
}
if _, ok := result.Attributes[provider.StorageClass]; !ok && result.Provider == string(provider.K8s_ProviderType) {
result.Attributes[provider.StorageClass] = storageClassName
}
return result, nil
} | [
"func",
"CharmStorageParams",
"(",
"controllerUUID",
"string",
",",
"storageClassName",
"string",
",",
"modelCfg",
"*",
"config",
".",
"Config",
",",
"poolName",
"string",
",",
"poolManager",
"poolmanager",
".",
"PoolManager",
",",
"registry",
"storage",
".",
"ProviderRegistry",
",",
")",
"(",
"params",
".",
"KubernetesFilesystemParams",
",",
"error",
")",
"{",
"// The defaults here are for operator storage.",
"// Workload storage will override these elsewhere.",
"var",
"size",
"uint64",
"=",
"1024",
"\n",
"tags",
":=",
"tags",
".",
"ResourceTags",
"(",
"names",
".",
"NewModelTag",
"(",
"modelCfg",
".",
"UUID",
"(",
")",
")",
",",
"names",
".",
"NewControllerTag",
"(",
"controllerUUID",
")",
",",
"modelCfg",
",",
")",
"\n\n",
"result",
":=",
"params",
".",
"KubernetesFilesystemParams",
"{",
"StorageName",
":",
"\"",
"\"",
",",
"Size",
":",
"size",
",",
"Provider",
":",
"string",
"(",
"provider",
".",
"K8s_ProviderType",
")",
",",
"Tags",
":",
"tags",
",",
"Attributes",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
",",
"}",
"\n\n",
"// The storage key value from the model config might correspond",
"// to a storage pool, unless there's been a specific storage pool",
"// requested.",
"// First, blank out the fallback pool name used in previous",
"// versions of Juju.",
"if",
"poolName",
"==",
"string",
"(",
"provider",
".",
"K8s_ProviderType",
")",
"{",
"poolName",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"maybePoolName",
":=",
"poolName",
"\n",
"if",
"maybePoolName",
"==",
"\"",
"\"",
"{",
"maybePoolName",
"=",
"storageClassName",
"\n",
"}",
"\n\n",
"providerType",
",",
"attrs",
",",
"err",
":=",
"poolStorageProvider",
"(",
"poolManager",
",",
"registry",
",",
"maybePoolName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"(",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"||",
"poolName",
"!=",
"\"",
"\"",
")",
"{",
"return",
"params",
".",
"KubernetesFilesystemParams",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
"==",
"nil",
"{",
"result",
".",
"Provider",
"=",
"string",
"(",
"providerType",
")",
"\n",
"if",
"len",
"(",
"attrs",
")",
">",
"0",
"{",
"result",
".",
"Attributes",
"=",
"attrs",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"result",
".",
"Attributes",
"[",
"provider",
".",
"StorageClass",
"]",
";",
"!",
"ok",
"&&",
"result",
".",
"Provider",
"==",
"string",
"(",
"provider",
".",
"K8s_ProviderType",
")",
"{",
"result",
".",
"Attributes",
"[",
"provider",
".",
"StorageClass",
"]",
"=",
"storageClassName",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // CharmStorageParams returns filesystem parameters needed
// to provision storage used for a charm operator or workload. | [
"CharmStorageParams",
"returns",
"filesystem",
"parameters",
"needed",
"to",
"provision",
"storage",
"used",
"for",
"a",
"charm",
"operator",
"or",
"workload",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/controller/caasoperatorprovisioner/provisioner.go#L152-L204 |
5,023 | juju/juju | provider/azure/internal/errorutils/errors.go | HandleCredentialError | func HandleCredentialError(err error, ctx context.ProviderCallContext) error {
MaybeInvalidateCredential(err, ctx)
return err
} | go | func HandleCredentialError(err error, ctx context.ProviderCallContext) error {
MaybeInvalidateCredential(err, ctx)
return err
} | [
"func",
"HandleCredentialError",
"(",
"err",
"error",
",",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"error",
"{",
"MaybeInvalidateCredential",
"(",
"err",
",",
"ctx",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // HandleCredentialError determines if given error relates to invalid credential.
// If it is, the credential is invalidated.
// Original error is returned untouched. | [
"HandleCredentialError",
"determines",
"if",
"given",
"error",
"relates",
"to",
"invalid",
"credential",
".",
"If",
"it",
"is",
"the",
"credential",
"is",
"invalidated",
".",
"Original",
"error",
"is",
"returned",
"untouched",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/errorutils/errors.go#L40-L43 |
5,024 | juju/juju | container/kvm/libvirt/domainxml.go | generateOSElement | func generateOSElement(p domainParams) OS {
switch p.Arch() {
case arch.ARM64:
return OS{
Type: OSType{
Arch: "aarch64",
Machine: "virt",
Text: "hvm",
},
Loader: &NVRAMCode{
Text: p.Loader(),
ReadOnly: "yes",
Type: "pflash",
},
}
default:
return OS{Type: OSType{Text: "hvm"}}
}
} | go | func generateOSElement(p domainParams) OS {
switch p.Arch() {
case arch.ARM64:
return OS{
Type: OSType{
Arch: "aarch64",
Machine: "virt",
Text: "hvm",
},
Loader: &NVRAMCode{
Text: p.Loader(),
ReadOnly: "yes",
Type: "pflash",
},
}
default:
return OS{Type: OSType{Text: "hvm"}}
}
} | [
"func",
"generateOSElement",
"(",
"p",
"domainParams",
")",
"OS",
"{",
"switch",
"p",
".",
"Arch",
"(",
")",
"{",
"case",
"arch",
".",
"ARM64",
":",
"return",
"OS",
"{",
"Type",
":",
"OSType",
"{",
"Arch",
":",
"\"",
"\"",
",",
"Machine",
":",
"\"",
"\"",
",",
"Text",
":",
"\"",
"\"",
",",
"}",
",",
"Loader",
":",
"&",
"NVRAMCode",
"{",
"Text",
":",
"p",
".",
"Loader",
"(",
")",
",",
"ReadOnly",
":",
"\"",
"\"",
",",
"Type",
":",
"\"",
"\"",
",",
"}",
",",
"}",
"\n",
"default",
":",
"return",
"OS",
"{",
"Type",
":",
"OSType",
"{",
"Text",
":",
"\"",
"\"",
"}",
"}",
"\n",
"}",
"\n",
"}"
] | // generateOSElement creates the architecture appropriate element details. | [
"generateOSElement",
"creates",
"the",
"architecture",
"appropriate",
"element",
"details",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/kvm/libvirt/domainxml.go#L137-L156 |
5,025 | juju/juju | container/kvm/libvirt/domainxml.go | generateFeaturesElement | func generateFeaturesElement(p domainParams) *Features {
if p.Arch() == arch.ARM64 {
return &Features{GIC: &GIC{Version: "host"}}
}
return nil
} | go | func generateFeaturesElement(p domainParams) *Features {
if p.Arch() == arch.ARM64 {
return &Features{GIC: &GIC{Version: "host"}}
}
return nil
} | [
"func",
"generateFeaturesElement",
"(",
"p",
"domainParams",
")",
"*",
"Features",
"{",
"if",
"p",
".",
"Arch",
"(",
")",
"==",
"arch",
".",
"ARM64",
"{",
"return",
"&",
"Features",
"{",
"GIC",
":",
"&",
"GIC",
"{",
"Version",
":",
"\"",
"\"",
"}",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // generateFeaturesElement generates the appropriate features element based on
// the architecture. | [
"generateFeaturesElement",
"generates",
"the",
"appropriate",
"features",
"element",
"based",
"on",
"the",
"architecture",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/kvm/libvirt/domainxml.go#L160-L165 |
5,026 | juju/juju | container/kvm/libvirt/domainxml.go | deviceID | func deviceID(i int) (string, error) {
if i < 0 || i > 25 {
return "", errors.Errorf("got %d but only support devices 0-25", i)
}
return fmt.Sprintf("vd%s", string('a'+i)), nil
} | go | func deviceID(i int) (string, error) {
if i < 0 || i > 25 {
return "", errors.Errorf("got %d but only support devices 0-25", i)
}
return fmt.Sprintf("vd%s", string('a'+i)), nil
} | [
"func",
"deviceID",
"(",
"i",
"int",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"i",
"<",
"0",
"||",
"i",
">",
"25",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"i",
")",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"string",
"(",
"'a'",
"+",
"i",
")",
")",
",",
"nil",
"\n",
"}"
] | // deviceID generates a device id from and int. The limit of 26 is arbitrary,
// but it seems unlikely we'll need more than a couple for our use case. | [
"deviceID",
"generates",
"a",
"device",
"id",
"from",
"and",
"int",
".",
"The",
"limit",
"of",
"26",
"is",
"arbitrary",
"but",
"it",
"seems",
"unlikely",
"we",
"ll",
"need",
"more",
"than",
"a",
"couple",
"for",
"our",
"use",
"case",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/container/kvm/libvirt/domainxml.go#L184-L189 |
5,027 | juju/juju | apiserver/logtransfer.go | Close | func (s *migrationLoggingStrategy) Close() error {
err := errors.Annotate(
s.tracker.Close(),
"closing last-sent tracker",
)
s.releaser()
return err
} | go | func (s *migrationLoggingStrategy) Close() error {
err := errors.Annotate(
s.tracker.Close(),
"closing last-sent tracker",
)
s.releaser()
return err
} | [
"func",
"(",
"s",
"*",
"migrationLoggingStrategy",
")",
"Close",
"(",
")",
"error",
"{",
"err",
":=",
"errors",
".",
"Annotate",
"(",
"s",
".",
"tracker",
".",
"Close",
"(",
")",
",",
"\"",
"\"",
",",
")",
"\n",
"s",
".",
"releaser",
"(",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // Close is part of the logsink.LogWriteCloser interface. | [
"Close",
"is",
"part",
"of",
"the",
"logsink",
".",
"LogWriteCloser",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/logtransfer.go#L71-L78 |
5,028 | juju/juju | worker/instancemutater/worker.go | Validate | func (config Config) Validate() error {
if config.Logger == nil {
return errors.NotValidf("nil Logger")
}
if config.Facade == nil {
return errors.NotValidf("nil Facade")
}
if config.Broker == nil {
return errors.NotValidf("nil Broker")
}
if config.AgentConfig == nil {
return errors.NotValidf("nil AgentConfig")
}
if config.Tag == nil {
return errors.NotValidf("nil Tag")
}
if _, ok := config.Tag.(names.MachineTag); !ok {
return errors.NotValidf("Tag")
}
if config.GetMachineWatcher == nil {
return errors.NotValidf("nil GetMachineWatcher")
}
if config.GetRequiredLXDProfiles == nil {
return errors.NotValidf("nil GetRequiredLXDProfiles")
}
return nil
} | go | func (config Config) Validate() error {
if config.Logger == nil {
return errors.NotValidf("nil Logger")
}
if config.Facade == nil {
return errors.NotValidf("nil Facade")
}
if config.Broker == nil {
return errors.NotValidf("nil Broker")
}
if config.AgentConfig == nil {
return errors.NotValidf("nil AgentConfig")
}
if config.Tag == nil {
return errors.NotValidf("nil Tag")
}
if _, ok := config.Tag.(names.MachineTag); !ok {
return errors.NotValidf("Tag")
}
if config.GetMachineWatcher == nil {
return errors.NotValidf("nil GetMachineWatcher")
}
if config.GetRequiredLXDProfiles == nil {
return errors.NotValidf("nil GetRequiredLXDProfiles")
}
return nil
} | [
"func",
"(",
"config",
"Config",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"config",
".",
"Logger",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"Facade",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"Broker",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"AgentConfig",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"Tag",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"config",
".",
"Tag",
".",
"(",
"names",
".",
"MachineTag",
")",
";",
"!",
"ok",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"GetMachineWatcher",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"config",
".",
"GetRequiredLXDProfiles",
"==",
"nil",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate checks for missing values from the configuration and checks that
// they conform to a given type. | [
"Validate",
"checks",
"for",
"missing",
"values",
"from",
"the",
"configuration",
"and",
"checks",
"that",
"they",
"conform",
"to",
"a",
"given",
"type",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancemutater/worker.go#L66-L92 |
5,029 | juju/juju | worker/instancemutater/worker.go | NewEnvironWorker | func NewEnvironWorker(config Config) (worker.Worker, error) {
config.GetMachineWatcher = config.Facade.WatchMachines
config.GetRequiredLXDProfiles = func(modelName string) []string {
return []string{"default", "juju-" + modelName}
}
return newWorker(config)
} | go | func NewEnvironWorker(config Config) (worker.Worker, error) {
config.GetMachineWatcher = config.Facade.WatchMachines
config.GetRequiredLXDProfiles = func(modelName string) []string {
return []string{"default", "juju-" + modelName}
}
return newWorker(config)
} | [
"func",
"NewEnvironWorker",
"(",
"config",
"Config",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"config",
".",
"GetMachineWatcher",
"=",
"config",
".",
"Facade",
".",
"WatchMachines",
"\n",
"config",
".",
"GetRequiredLXDProfiles",
"=",
"func",
"(",
"modelName",
"string",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"+",
"modelName",
"}",
"\n",
"}",
"\n",
"return",
"newWorker",
"(",
"config",
")",
"\n",
"}"
] | // NewEnvironWorker returns a worker that keeps track of
// the machines in the state and polls their instance
// for addition or removal changes. | [
"NewEnvironWorker",
"returns",
"a",
"worker",
"that",
"keeps",
"track",
"of",
"the",
"machines",
"in",
"the",
"state",
"and",
"polls",
"their",
"instance",
"for",
"addition",
"or",
"removal",
"changes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancemutater/worker.go#L97-L103 |
5,030 | juju/juju | worker/instancemutater/worker.go | NewContainerWorker | func NewContainerWorker(config Config) (worker.Worker, error) {
m, err := config.Facade.Machine(config.Tag.(names.MachineTag))
if err != nil {
return nil, errors.Trace(err)
}
config.GetRequiredLXDProfiles = func(_ string) []string { return []string{"default"} }
config.GetMachineWatcher = m.WatchContainers
return newWorker(config)
} | go | func NewContainerWorker(config Config) (worker.Worker, error) {
m, err := config.Facade.Machine(config.Tag.(names.MachineTag))
if err != nil {
return nil, errors.Trace(err)
}
config.GetRequiredLXDProfiles = func(_ string) []string { return []string{"default"} }
config.GetMachineWatcher = m.WatchContainers
return newWorker(config)
} | [
"func",
"NewContainerWorker",
"(",
"config",
"Config",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"config",
".",
"Facade",
".",
"Machine",
"(",
"config",
".",
"Tag",
".",
"(",
"names",
".",
"MachineTag",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"config",
".",
"GetRequiredLXDProfiles",
"=",
"func",
"(",
"_",
"string",
")",
"[",
"]",
"string",
"{",
"return",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
"}",
"\n",
"config",
".",
"GetMachineWatcher",
"=",
"m",
".",
"WatchContainers",
"\n",
"return",
"newWorker",
"(",
"config",
")",
"\n",
"}"
] | // NewContainerWorker returns a worker that keeps track of
// the containers in the state for this machine agent and
// polls their instance for addition or removal changes. | [
"NewContainerWorker",
"returns",
"a",
"worker",
"that",
"keeps",
"track",
"of",
"the",
"containers",
"in",
"the",
"state",
"for",
"this",
"machine",
"agent",
"and",
"polls",
"their",
"instance",
"for",
"addition",
"or",
"removal",
"changes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancemutater/worker.go#L108-L116 |
5,031 | juju/juju | worker/instancemutater/worker.go | getMachine | func (w *mutaterWorker) getMachine(tag names.MachineTag) (instancemutater.MutaterMachine, error) {
m, err := w.facade.Machine(tag)
return m, err
} | go | func (w *mutaterWorker) getMachine(tag names.MachineTag) (instancemutater.MutaterMachine, error) {
m, err := w.facade.Machine(tag)
return m, err
} | [
"func",
"(",
"w",
"*",
"mutaterWorker",
")",
"getMachine",
"(",
"tag",
"names",
".",
"MachineTag",
")",
"(",
"instancemutater",
".",
"MutaterMachine",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"w",
".",
"facade",
".",
"Machine",
"(",
"tag",
")",
"\n",
"return",
"m",
",",
"err",
"\n",
"}"
] | // getMachine is part of the MachineContext interface. | [
"getMachine",
"is",
"part",
"of",
"the",
"MachineContext",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancemutater/worker.go#L209-L212 |
5,032 | juju/juju | worker/instancemutater/worker.go | add | func (w *mutaterWorker) add(new worker.Worker) error {
return w.catacomb.Add(new)
} | go | func (w *mutaterWorker) add(new worker.Worker) error {
return w.catacomb.Add(new)
} | [
"func",
"(",
"w",
"*",
"mutaterWorker",
")",
"add",
"(",
"new",
"worker",
".",
"Worker",
")",
"error",
"{",
"return",
"w",
".",
"catacomb",
".",
"Add",
"(",
"new",
")",
"\n",
"}"
] | // add is part of the lifetimeContext interface. | [
"add",
"is",
"part",
"of",
"the",
"lifetimeContext",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/instancemutater/worker.go#L240-L242 |
5,033 | juju/juju | agent/uninstall.go | SetCanUninstall | func SetCanUninstall(a Agent) error {
tag := a.CurrentConfig().Tag()
if _, ok := tag.(names.MachineTag); !ok {
logger.Debugf("cannot uninstall non-machine agent %q", tag)
return nil
}
logger.Infof("marking agent ready for uninstall")
return ioutil.WriteFile(uninstallFile(a), nil, 0644)
} | go | func SetCanUninstall(a Agent) error {
tag := a.CurrentConfig().Tag()
if _, ok := tag.(names.MachineTag); !ok {
logger.Debugf("cannot uninstall non-machine agent %q", tag)
return nil
}
logger.Infof("marking agent ready for uninstall")
return ioutil.WriteFile(uninstallFile(a), nil, 0644)
} | [
"func",
"SetCanUninstall",
"(",
"a",
"Agent",
")",
"error",
"{",
"tag",
":=",
"a",
".",
"CurrentConfig",
"(",
")",
".",
"Tag",
"(",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"tag",
".",
"(",
"names",
".",
"MachineTag",
")",
";",
"!",
"ok",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"tag",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"ioutil",
".",
"WriteFile",
"(",
"uninstallFile",
"(",
"a",
")",
",",
"nil",
",",
"0644",
")",
"\n",
"}"
] | // SetCanUninstall creates the uninstall file in the data dir. It does
// nothing if the supplied agent doesn't have a machine tag. | [
"SetCanUninstall",
"creates",
"the",
"uninstall",
"file",
"in",
"the",
"data",
"dir",
".",
"It",
"does",
"nothing",
"if",
"the",
"supplied",
"agent",
"doesn",
"t",
"have",
"a",
"machine",
"tag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/uninstall.go#L30-L38 |
5,034 | juju/juju | agent/uninstall.go | CanUninstall | func CanUninstall(a Agent) bool {
if _, err := os.Stat(uninstallFile(a)); err != nil {
logger.Debugf("agent not marked ready for uninstall")
return false
}
logger.Infof("agent already marked ready for uninstall")
return true
} | go | func CanUninstall(a Agent) bool {
if _, err := os.Stat(uninstallFile(a)); err != nil {
logger.Debugf("agent not marked ready for uninstall")
return false
}
logger.Infof("agent already marked ready for uninstall")
return true
} | [
"func",
"CanUninstall",
"(",
"a",
"Agent",
")",
"bool",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"uninstallFile",
"(",
"a",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"return",
"true",
"\n",
"}"
] | // CanUninstall returns true if the uninstall file exists in the agent's
// data dir. If it encounters an error, it fails safe and returns false. | [
"CanUninstall",
"returns",
"true",
"if",
"the",
"uninstall",
"file",
"exists",
"in",
"the",
"agent",
"s",
"data",
"dir",
".",
"If",
"it",
"encounters",
"an",
"error",
"it",
"fails",
"safe",
"and",
"returns",
"false",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/agent/uninstall.go#L42-L49 |
5,035 | juju/juju | worker/modelupgrader/worker.go | newWaitWorker | func newWaitWorker(config Config, targetVersion int) (worker.Worker, error) {
watcher, err := config.Facade.WatchModelEnvironVersion(config.ModelTag)
if err != nil {
return nil, errors.Trace(err)
}
ww := waitWorker{
watcher: watcher,
facade: config.Facade,
modelTag: config.ModelTag,
gate: config.GateUnlocker,
targetVersion: targetVersion,
}
if err := catacomb.Invoke(catacomb.Plan{
Site: &ww.catacomb,
Init: []worker.Worker{watcher},
Work: ww.loop,
}); err != nil {
return nil, errors.Trace(err)
}
return &ww, nil
} | go | func newWaitWorker(config Config, targetVersion int) (worker.Worker, error) {
watcher, err := config.Facade.WatchModelEnvironVersion(config.ModelTag)
if err != nil {
return nil, errors.Trace(err)
}
ww := waitWorker{
watcher: watcher,
facade: config.Facade,
modelTag: config.ModelTag,
gate: config.GateUnlocker,
targetVersion: targetVersion,
}
if err := catacomb.Invoke(catacomb.Plan{
Site: &ww.catacomb,
Init: []worker.Worker{watcher},
Work: ww.loop,
}); err != nil {
return nil, errors.Trace(err)
}
return &ww, nil
} | [
"func",
"newWaitWorker",
"(",
"config",
"Config",
",",
"targetVersion",
"int",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"watcher",
",",
"err",
":=",
"config",
".",
"Facade",
".",
"WatchModelEnvironVersion",
"(",
"config",
".",
"ModelTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ww",
":=",
"waitWorker",
"{",
"watcher",
":",
"watcher",
",",
"facade",
":",
"config",
".",
"Facade",
",",
"modelTag",
":",
"config",
".",
"ModelTag",
",",
"gate",
":",
"config",
".",
"GateUnlocker",
",",
"targetVersion",
":",
"targetVersion",
",",
"}",
"\n",
"if",
"err",
":=",
"catacomb",
".",
"Invoke",
"(",
"catacomb",
".",
"Plan",
"{",
"Site",
":",
"&",
"ww",
".",
"catacomb",
",",
"Init",
":",
"[",
"]",
"worker",
".",
"Worker",
"{",
"watcher",
"}",
",",
"Work",
":",
"ww",
".",
"loop",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"ww",
",",
"nil",
"\n",
"}"
] | // newWaitWorker returns a worker that waits for the controller leader to run
// the upgrade steps and update the model's environ version, and then unlocks
// the gate. | [
"newWaitWorker",
"returns",
"a",
"worker",
"that",
"waits",
"for",
"the",
"controller",
"leader",
"to",
"run",
"the",
"upgrade",
"steps",
"and",
"update",
"the",
"model",
"s",
"environ",
"version",
"and",
"then",
"unlocks",
"the",
"gate",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/modelupgrader/worker.go#L111-L131 |
5,036 | juju/juju | worker/modelupgrader/worker.go | newUpgradeWorker | func newUpgradeWorker(config Config, targetVersion int) (worker.Worker, error) {
currentVersion, err := config.Facade.ModelEnvironVersion(config.ModelTag)
if err != nil {
return nil, errors.Trace(err)
}
return jujuworker.NewSimpleWorker(func(<-chan struct{}) error {
// NOTE(axw) the abort channel is ignored, because upgrade
// steps are not interruptible. If we find they need to be
// interruptible, we should consider passing through a
// context.Context for cancellation, and cancelling it if
// the abort channel is signalled.
setVersion := func(v int) error {
return config.Facade.SetModelEnvironVersion(config.ModelTag, v)
}
setStatus := func(s status.Status, info string) error {
return config.Facade.SetModelStatus(config.ModelTag, s, info, nil)
}
if targetVersion > currentVersion {
if err := setStatus(status.Busy, fmt.Sprintf(
"upgrading environ from version %d to %d",
currentVersion, targetVersion,
)); err != nil {
return errors.Trace(err)
}
}
if err := runEnvironUpgradeSteps(
config.Environ,
config.ControllerTag,
config.ModelTag,
currentVersion,
targetVersion,
setVersion,
common.NewCloudCallContext(config.CredentialAPI, nil),
); err != nil {
info := fmt.Sprintf("failed to upgrade environ: %s", err)
if err := setStatus(status.Error, info); err != nil {
logger.Warningf("failed to update model status: %v", err)
}
return errors.Annotate(err, "upgrading environ")
}
if err := setStatus(status.Available, ""); err != nil {
return errors.Trace(err)
}
config.GateUnlocker.Unlock()
return nil
}), nil
} | go | func newUpgradeWorker(config Config, targetVersion int) (worker.Worker, error) {
currentVersion, err := config.Facade.ModelEnvironVersion(config.ModelTag)
if err != nil {
return nil, errors.Trace(err)
}
return jujuworker.NewSimpleWorker(func(<-chan struct{}) error {
// NOTE(axw) the abort channel is ignored, because upgrade
// steps are not interruptible. If we find they need to be
// interruptible, we should consider passing through a
// context.Context for cancellation, and cancelling it if
// the abort channel is signalled.
setVersion := func(v int) error {
return config.Facade.SetModelEnvironVersion(config.ModelTag, v)
}
setStatus := func(s status.Status, info string) error {
return config.Facade.SetModelStatus(config.ModelTag, s, info, nil)
}
if targetVersion > currentVersion {
if err := setStatus(status.Busy, fmt.Sprintf(
"upgrading environ from version %d to %d",
currentVersion, targetVersion,
)); err != nil {
return errors.Trace(err)
}
}
if err := runEnvironUpgradeSteps(
config.Environ,
config.ControllerTag,
config.ModelTag,
currentVersion,
targetVersion,
setVersion,
common.NewCloudCallContext(config.CredentialAPI, nil),
); err != nil {
info := fmt.Sprintf("failed to upgrade environ: %s", err)
if err := setStatus(status.Error, info); err != nil {
logger.Warningf("failed to update model status: %v", err)
}
return errors.Annotate(err, "upgrading environ")
}
if err := setStatus(status.Available, ""); err != nil {
return errors.Trace(err)
}
config.GateUnlocker.Unlock()
return nil
}), nil
} | [
"func",
"newUpgradeWorker",
"(",
"config",
"Config",
",",
"targetVersion",
"int",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"currentVersion",
",",
"err",
":=",
"config",
".",
"Facade",
".",
"ModelEnvironVersion",
"(",
"config",
".",
"ModelTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"jujuworker",
".",
"NewSimpleWorker",
"(",
"func",
"(",
"<-",
"chan",
"struct",
"{",
"}",
")",
"error",
"{",
"// NOTE(axw) the abort channel is ignored, because upgrade",
"// steps are not interruptible. If we find they need to be",
"// interruptible, we should consider passing through a",
"// context.Context for cancellation, and cancelling it if",
"// the abort channel is signalled.",
"setVersion",
":=",
"func",
"(",
"v",
"int",
")",
"error",
"{",
"return",
"config",
".",
"Facade",
".",
"SetModelEnvironVersion",
"(",
"config",
".",
"ModelTag",
",",
"v",
")",
"\n",
"}",
"\n",
"setStatus",
":=",
"func",
"(",
"s",
"status",
".",
"Status",
",",
"info",
"string",
")",
"error",
"{",
"return",
"config",
".",
"Facade",
".",
"SetModelStatus",
"(",
"config",
".",
"ModelTag",
",",
"s",
",",
"info",
",",
"nil",
")",
"\n",
"}",
"\n",
"if",
"targetVersion",
">",
"currentVersion",
"{",
"if",
"err",
":=",
"setStatus",
"(",
"status",
".",
"Busy",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"currentVersion",
",",
"targetVersion",
",",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"runEnvironUpgradeSteps",
"(",
"config",
".",
"Environ",
",",
"config",
".",
"ControllerTag",
",",
"config",
".",
"ModelTag",
",",
"currentVersion",
",",
"targetVersion",
",",
"setVersion",
",",
"common",
".",
"NewCloudCallContext",
"(",
"config",
".",
"CredentialAPI",
",",
"nil",
")",
",",
")",
";",
"err",
"!=",
"nil",
"{",
"info",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"if",
"err",
":=",
"setStatus",
"(",
"status",
".",
"Error",
",",
"info",
")",
";",
"err",
"!=",
"nil",
"{",
"logger",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"setStatus",
"(",
"status",
".",
"Available",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"config",
".",
"GateUnlocker",
".",
"Unlock",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}",
")",
",",
"nil",
"\n",
"}"
] | // newUpgradeWorker returns a worker that runs the upgrade steps, updates the
// model's environ version, and unlocks the gate. | [
"newUpgradeWorker",
"returns",
"a",
"worker",
"that",
"runs",
"the",
"upgrade",
"steps",
"updates",
"the",
"model",
"s",
"environ",
"version",
"and",
"unlocks",
"the",
"gate",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/modelupgrader/worker.go#L176-L223 |
5,037 | juju/juju | api/caasoperatorprovisioner/client.go | SetPasswords | func (c *Client) SetPasswords(appPasswords []ApplicationPassword) (params.ErrorResults, error) {
var result params.ErrorResults
args := params.EntityPasswords{Changes: make([]params.EntityPassword, len(appPasswords))}
for i, p := range appPasswords {
args.Changes[i] = params.EntityPassword{
Tag: names.NewApplicationTag(p.Name).String(), Password: p.Password,
}
}
err := c.facade.FacadeCall("SetPasswords", args, &result)
if err != nil {
return params.ErrorResults{}, err
}
if len(result.Results) != len(args.Changes) {
return params.ErrorResults{}, errors.Errorf("expected %d result(s), got %d", len(args.Changes), len(result.Results))
}
return result, nil
} | go | func (c *Client) SetPasswords(appPasswords []ApplicationPassword) (params.ErrorResults, error) {
var result params.ErrorResults
args := params.EntityPasswords{Changes: make([]params.EntityPassword, len(appPasswords))}
for i, p := range appPasswords {
args.Changes[i] = params.EntityPassword{
Tag: names.NewApplicationTag(p.Name).String(), Password: p.Password,
}
}
err := c.facade.FacadeCall("SetPasswords", args, &result)
if err != nil {
return params.ErrorResults{}, err
}
if len(result.Results) != len(args.Changes) {
return params.ErrorResults{}, errors.Errorf("expected %d result(s), got %d", len(args.Changes), len(result.Results))
}
return result, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"SetPasswords",
"(",
"appPasswords",
"[",
"]",
"ApplicationPassword",
")",
"(",
"params",
".",
"ErrorResults",
",",
"error",
")",
"{",
"var",
"result",
"params",
".",
"ErrorResults",
"\n",
"args",
":=",
"params",
".",
"EntityPasswords",
"{",
"Changes",
":",
"make",
"(",
"[",
"]",
"params",
".",
"EntityPassword",
",",
"len",
"(",
"appPasswords",
")",
")",
"}",
"\n",
"for",
"i",
",",
"p",
":=",
"range",
"appPasswords",
"{",
"args",
".",
"Changes",
"[",
"i",
"]",
"=",
"params",
".",
"EntityPassword",
"{",
"Tag",
":",
"names",
".",
"NewApplicationTag",
"(",
"p",
".",
"Name",
")",
".",
"String",
"(",
")",
",",
"Password",
":",
"p",
".",
"Password",
",",
"}",
"\n",
"}",
"\n",
"err",
":=",
"c",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"result",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"result",
".",
"Results",
")",
"!=",
"len",
"(",
"args",
".",
"Changes",
")",
"{",
"return",
"params",
".",
"ErrorResults",
"{",
"}",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"args",
".",
"Changes",
")",
",",
"len",
"(",
"result",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // SetPasswords sets API passwords for the specified applications. | [
"SetPasswords",
"sets",
"API",
"passwords",
"for",
"the",
"specified",
"applications",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/caasoperatorprovisioner/client.go#L54-L70 |
5,038 | juju/juju | worker/uniter/runcommands/runcommands.go | NewCommandsResolver | func NewCommandsResolver(commands Commands, commandCompleted func(string)) resolver.Resolver {
return &commandsResolver{commands, commandCompleted}
} | go | func NewCommandsResolver(commands Commands, commandCompleted func(string)) resolver.Resolver {
return &commandsResolver{commands, commandCompleted}
} | [
"func",
"NewCommandsResolver",
"(",
"commands",
"Commands",
",",
"commandCompleted",
"func",
"(",
"string",
")",
")",
"resolver",
".",
"Resolver",
"{",
"return",
"&",
"commandsResolver",
"{",
"commands",
",",
"commandCompleted",
"}",
"\n",
"}"
] | // NewCommandsResolver returns a new Resolver that returns operations to
// execute "juju run" commands.
//
// The returned resolver's NextOp method will return operations to execute
// run commands whenever the remote state's "Commands" is non-empty, by
// taking the first ID in the sequence and fetching the command arguments
// from the Commands interface passed into this function. When the command
// execution operation is committed, the ID of the command is passed to the
// "commandCompleted" callback. | [
"NewCommandsResolver",
"returns",
"a",
"new",
"Resolver",
"that",
"returns",
"operations",
"to",
"execute",
"juju",
"run",
"commands",
".",
"The",
"returned",
"resolver",
"s",
"NextOp",
"method",
"will",
"return",
"operations",
"to",
"execute",
"run",
"commands",
"whenever",
"the",
"remote",
"state",
"s",
"Commands",
"is",
"non",
"-",
"empty",
"by",
"taking",
"the",
"first",
"ID",
"in",
"the",
"sequence",
"and",
"fetching",
"the",
"command",
"arguments",
"from",
"the",
"Commands",
"interface",
"passed",
"into",
"this",
"function",
".",
"When",
"the",
"command",
"execution",
"operation",
"is",
"committed",
"the",
"ID",
"of",
"the",
"command",
"is",
"passed",
"to",
"the",
"commandCompleted",
"callback",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runcommands/runcommands.go#L85-L87 |
5,039 | juju/juju | worker/uniter/runcommands/runcommands.go | NextOp | func (s *commandsResolver) NextOp(
localState resolver.LocalState,
remoteState remotestate.Snapshot,
opFactory operation.Factory,
) (operation.Operation, error) {
if len(remoteState.Commands) == 0 {
return nil, resolver.ErrNoOperation
}
id := remoteState.Commands[0]
op, err := opFactory.NewCommands(s.commands.GetCommand(id))
if err != nil {
return nil, err
}
commandCompleted := func() {
s.commands.RemoveCommand(id)
s.commandCompleted(id)
}
return &commandCompleter{op, commandCompleted}, nil
} | go | func (s *commandsResolver) NextOp(
localState resolver.LocalState,
remoteState remotestate.Snapshot,
opFactory operation.Factory,
) (operation.Operation, error) {
if len(remoteState.Commands) == 0 {
return nil, resolver.ErrNoOperation
}
id := remoteState.Commands[0]
op, err := opFactory.NewCommands(s.commands.GetCommand(id))
if err != nil {
return nil, err
}
commandCompleted := func() {
s.commands.RemoveCommand(id)
s.commandCompleted(id)
}
return &commandCompleter{op, commandCompleted}, nil
} | [
"func",
"(",
"s",
"*",
"commandsResolver",
")",
"NextOp",
"(",
"localState",
"resolver",
".",
"LocalState",
",",
"remoteState",
"remotestate",
".",
"Snapshot",
",",
"opFactory",
"operation",
".",
"Factory",
",",
")",
"(",
"operation",
".",
"Operation",
",",
"error",
")",
"{",
"if",
"len",
"(",
"remoteState",
".",
"Commands",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"resolver",
".",
"ErrNoOperation",
"\n",
"}",
"\n",
"id",
":=",
"remoteState",
".",
"Commands",
"[",
"0",
"]",
"\n",
"op",
",",
"err",
":=",
"opFactory",
".",
"NewCommands",
"(",
"s",
".",
"commands",
".",
"GetCommand",
"(",
"id",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"commandCompleted",
":=",
"func",
"(",
")",
"{",
"s",
".",
"commands",
".",
"RemoveCommand",
"(",
"id",
")",
"\n",
"s",
".",
"commandCompleted",
"(",
"id",
")",
"\n",
"}",
"\n",
"return",
"&",
"commandCompleter",
"{",
"op",
",",
"commandCompleted",
"}",
",",
"nil",
"\n",
"}"
] | // NextOp is part of the resolver.Resolver interface. | [
"NextOp",
"is",
"part",
"of",
"the",
"resolver",
".",
"Resolver",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/runcommands/runcommands.go#L90-L108 |
5,040 | juju/juju | provider/oci/environ.go | InstanceAvailabilityZoneNames | func (e *Environ) InstanceAvailabilityZoneNames(ctx envcontext.ProviderCallContext, ids []instance.Id) ([]string, error) {
instances, err := e.Instances(ctx, ids)
if err != nil && err != environs.ErrPartialInstances {
providerCommon.HandleCredentialError(err, ctx)
return nil, err
}
zones := []string{}
for _, inst := range instances {
oInst := inst.(*ociInstance)
zones = append(zones, oInst.availabilityZone())
}
if len(zones) < len(ids) {
return zones, environs.ErrPartialInstances
}
return zones, nil
} | go | func (e *Environ) InstanceAvailabilityZoneNames(ctx envcontext.ProviderCallContext, ids []instance.Id) ([]string, error) {
instances, err := e.Instances(ctx, ids)
if err != nil && err != environs.ErrPartialInstances {
providerCommon.HandleCredentialError(err, ctx)
return nil, err
}
zones := []string{}
for _, inst := range instances {
oInst := inst.(*ociInstance)
zones = append(zones, oInst.availabilityZone())
}
if len(zones) < len(ids) {
return zones, environs.ErrPartialInstances
}
return zones, nil
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"InstanceAvailabilityZoneNames",
"(",
"ctx",
"envcontext",
".",
"ProviderCallContext",
",",
"ids",
"[",
"]",
"instance",
".",
"Id",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"instances",
",",
"err",
":=",
"e",
".",
"Instances",
"(",
"ctx",
",",
"ids",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"environs",
".",
"ErrPartialInstances",
"{",
"providerCommon",
".",
"HandleCredentialError",
"(",
"err",
",",
"ctx",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"zones",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"inst",
":=",
"range",
"instances",
"{",
"oInst",
":=",
"inst",
".",
"(",
"*",
"ociInstance",
")",
"\n",
"zones",
"=",
"append",
"(",
"zones",
",",
"oInst",
".",
"availabilityZone",
"(",
")",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"zones",
")",
"<",
"len",
"(",
"ids",
")",
"{",
"return",
"zones",
",",
"environs",
".",
"ErrPartialInstances",
"\n",
"}",
"\n",
"return",
"zones",
",",
"nil",
"\n",
"}"
] | // InstanceAvailabilityZoneNames implements common.ZonedEnviron. | [
"InstanceAvailabilityZoneNames",
"implements",
"common",
".",
"ZonedEnviron",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L202-L217 |
5,041 | juju/juju | provider/oci/environ.go | DeriveAvailabilityZones | func (e *Environ) DeriveAvailabilityZones(ctx envcontext.ProviderCallContext, args environs.StartInstanceParams) ([]string, error) {
return nil, nil
} | go | func (e *Environ) DeriveAvailabilityZones(ctx envcontext.ProviderCallContext, args environs.StartInstanceParams) ([]string, error) {
return nil, nil
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"DeriveAvailabilityZones",
"(",
"ctx",
"envcontext",
".",
"ProviderCallContext",
",",
"args",
"environs",
".",
"StartInstanceParams",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}"
] | // DeriveAvailabilityZones implements common.ZonedEnviron. | [
"DeriveAvailabilityZones",
"implements",
"common",
".",
"ZonedEnviron",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L220-L222 |
5,042 | juju/juju | provider/oci/environ.go | Instances | func (e *Environ) Instances(ctx envcontext.ProviderCallContext, ids []instance.Id) ([]instances.Instance, error) {
if len(ids) == 0 {
return nil, nil
}
ociInstances, err := e.getOciInstances(ctx, ids...)
if err != nil && err != environs.ErrPartialInstances {
providerCommon.HandleCredentialError(err, ctx)
return nil, errors.Trace(err)
}
ret := []instances.Instance{}
for _, val := range ociInstances {
ret = append(ret, val)
}
if len(ret) < len(ids) {
return ret, environs.ErrPartialInstances
}
return ret, nil
} | go | func (e *Environ) Instances(ctx envcontext.ProviderCallContext, ids []instance.Id) ([]instances.Instance, error) {
if len(ids) == 0 {
return nil, nil
}
ociInstances, err := e.getOciInstances(ctx, ids...)
if err != nil && err != environs.ErrPartialInstances {
providerCommon.HandleCredentialError(err, ctx)
return nil, errors.Trace(err)
}
ret := []instances.Instance{}
for _, val := range ociInstances {
ret = append(ret, val)
}
if len(ret) < len(ids) {
return ret, environs.ErrPartialInstances
}
return ret, nil
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"Instances",
"(",
"ctx",
"envcontext",
".",
"ProviderCallContext",
",",
"ids",
"[",
"]",
"instance",
".",
"Id",
")",
"(",
"[",
"]",
"instances",
".",
"Instance",
",",
"error",
")",
"{",
"if",
"len",
"(",
"ids",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"ociInstances",
",",
"err",
":=",
"e",
".",
"getOciInstances",
"(",
"ctx",
",",
"ids",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"err",
"!=",
"environs",
".",
"ErrPartialInstances",
"{",
"providerCommon",
".",
"HandleCredentialError",
"(",
"err",
",",
"ctx",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"ret",
":=",
"[",
"]",
"instances",
".",
"Instance",
"{",
"}",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"ociInstances",
"{",
"ret",
"=",
"append",
"(",
"ret",
",",
"val",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"ret",
")",
"<",
"len",
"(",
"ids",
")",
"{",
"return",
"ret",
",",
"environs",
".",
"ErrPartialInstances",
"\n",
"}",
"\n",
"return",
"ret",
",",
"nil",
"\n",
"}"
] | // Instances implements environs.Environ. | [
"Instances",
"implements",
"environs",
".",
"Environ",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L275-L294 |
5,043 | juju/juju | provider/oci/environ.go | AdoptResources | func (e *Environ) AdoptResources(ctx envcontext.ProviderCallContext, controllerUUID string, fromVersion version.Number) error {
return errors.NotImplementedf("AdoptResources")
} | go | func (e *Environ) AdoptResources(ctx envcontext.ProviderCallContext, controllerUUID string, fromVersion version.Number) error {
return errors.NotImplementedf("AdoptResources")
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"AdoptResources",
"(",
"ctx",
"envcontext",
".",
"ProviderCallContext",
",",
"controllerUUID",
"string",
",",
"fromVersion",
"version",
".",
"Number",
")",
"error",
"{",
"return",
"errors",
".",
"NotImplementedf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // AdoptResources implements environs.Environ. | [
"AdoptResources",
"implements",
"environs",
".",
"Environ",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L323-L325 |
5,044 | juju/juju | provider/oci/environ.go | ConstraintsValidator | func (e *Environ) ConstraintsValidator(ctx envcontext.ProviderCallContext) (constraints.Validator, error) {
// list of unsupported OCI provider constraints
unsupportedConstraints := []string{
constraints.Container,
constraints.VirtType,
constraints.Tags,
}
validator := constraints.NewValidator()
validator.RegisterUnsupported(unsupportedConstraints)
validator.RegisterVocabulary(constraints.Arch, []string{arch.AMD64})
logger.Infof("Returning constraints validator: %v", validator)
return validator, nil
} | go | func (e *Environ) ConstraintsValidator(ctx envcontext.ProviderCallContext) (constraints.Validator, error) {
// list of unsupported OCI provider constraints
unsupportedConstraints := []string{
constraints.Container,
constraints.VirtType,
constraints.Tags,
}
validator := constraints.NewValidator()
validator.RegisterUnsupported(unsupportedConstraints)
validator.RegisterVocabulary(constraints.Arch, []string{arch.AMD64})
logger.Infof("Returning constraints validator: %v", validator)
return validator, nil
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"ConstraintsValidator",
"(",
"ctx",
"envcontext",
".",
"ProviderCallContext",
")",
"(",
"constraints",
".",
"Validator",
",",
"error",
")",
"{",
"// list of unsupported OCI provider constraints",
"unsupportedConstraints",
":=",
"[",
"]",
"string",
"{",
"constraints",
".",
"Container",
",",
"constraints",
".",
"VirtType",
",",
"constraints",
".",
"Tags",
",",
"}",
"\n\n",
"validator",
":=",
"constraints",
".",
"NewValidator",
"(",
")",
"\n",
"validator",
".",
"RegisterUnsupported",
"(",
"unsupportedConstraints",
")",
"\n",
"validator",
".",
"RegisterVocabulary",
"(",
"constraints",
".",
"Arch",
",",
"[",
"]",
"string",
"{",
"arch",
".",
"AMD64",
"}",
")",
"\n",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"validator",
")",
"\n",
"return",
"validator",
",",
"nil",
"\n",
"}"
] | // ConstraintsValidator implements environs.Environ. | [
"ConstraintsValidator",
"implements",
"environs",
".",
"Environ",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L328-L341 |
5,045 | juju/juju | provider/oci/environ.go | SetConfig | func (e *Environ) SetConfig(cfg *config.Config) error {
ecfg, err := e.p.newConfig(cfg)
if err != nil {
return err
}
e.ecfgMutex.Lock()
defer e.ecfgMutex.Unlock()
e.ecfgObj = ecfg
return nil
} | go | func (e *Environ) SetConfig(cfg *config.Config) error {
ecfg, err := e.p.newConfig(cfg)
if err != nil {
return err
}
e.ecfgMutex.Lock()
defer e.ecfgMutex.Unlock()
e.ecfgObj = ecfg
return nil
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"SetConfig",
"(",
"cfg",
"*",
"config",
".",
"Config",
")",
"error",
"{",
"ecfg",
",",
"err",
":=",
"e",
".",
"p",
".",
"newConfig",
"(",
"cfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"e",
".",
"ecfgMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"ecfgMutex",
".",
"Unlock",
"(",
")",
"\n",
"e",
".",
"ecfgObj",
"=",
"ecfg",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // SetConfig implements environs.Environ. | [
"SetConfig",
"implements",
"environs",
".",
"Environ",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L344-L355 |
5,046 | juju/juju | provider/oci/environ.go | ControllerInstances | func (e *Environ) ControllerInstances(ctx envcontext.ProviderCallContext, controllerUUID string) ([]instance.Id, error) {
tags := map[string]string{
tags.JujuController: controllerUUID,
tags.JujuIsController: "true",
}
instances, err := e.allInstances(ctx, tags)
if err != nil {
providerCommon.HandleCredentialError(err, ctx)
return nil, errors.Trace(err)
}
ids := []instance.Id{}
for _, val := range instances {
ids = append(ids, val.Id())
}
return ids, nil
} | go | func (e *Environ) ControllerInstances(ctx envcontext.ProviderCallContext, controllerUUID string) ([]instance.Id, error) {
tags := map[string]string{
tags.JujuController: controllerUUID,
tags.JujuIsController: "true",
}
instances, err := e.allInstances(ctx, tags)
if err != nil {
providerCommon.HandleCredentialError(err, ctx)
return nil, errors.Trace(err)
}
ids := []instance.Id{}
for _, val := range instances {
ids = append(ids, val.Id())
}
return ids, nil
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"ControllerInstances",
"(",
"ctx",
"envcontext",
".",
"ProviderCallContext",
",",
"controllerUUID",
"string",
")",
"(",
"[",
"]",
"instance",
".",
"Id",
",",
"error",
")",
"{",
"tags",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"tags",
".",
"JujuController",
":",
"controllerUUID",
",",
"tags",
".",
"JujuIsController",
":",
"\"",
"\"",
",",
"}",
"\n",
"instances",
",",
"err",
":=",
"e",
".",
"allInstances",
"(",
"ctx",
",",
"tags",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"providerCommon",
".",
"HandleCredentialError",
"(",
"err",
",",
"ctx",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ids",
":=",
"[",
"]",
"instance",
".",
"Id",
"{",
"}",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"instances",
"{",
"ids",
"=",
"append",
"(",
"ids",
",",
"val",
".",
"Id",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"ids",
",",
"nil",
"\n",
"}"
] | // ControllerInstances implements environs.Environ. | [
"ControllerInstances",
"implements",
"environs",
".",
"Environ",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L365-L380 |
5,047 | juju/juju | provider/oci/environ.go | Destroy | func (e *Environ) Destroy(ctx envcontext.ProviderCallContext) error {
return common.Destroy(e, ctx)
} | go | func (e *Environ) Destroy(ctx envcontext.ProviderCallContext) error {
return common.Destroy(e, ctx)
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"Destroy",
"(",
"ctx",
"envcontext",
".",
"ProviderCallContext",
")",
"error",
"{",
"return",
"common",
".",
"Destroy",
"(",
"e",
",",
"ctx",
")",
"\n",
"}"
] | // Destroy implements environs.Environ. | [
"Destroy",
"implements",
"environs",
".",
"Environ",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L383-L385 |
5,048 | juju/juju | provider/oci/environ.go | DestroyController | func (e *Environ) DestroyController(ctx envcontext.ProviderCallContext, controllerUUID string) error {
err := e.Destroy(ctx)
if err != nil {
providerCommon.HandleCredentialError(err, ctx)
logger.Errorf("Failed to destroy environment through controller: %s", errors.Trace(err))
}
instances, err := e.allControllerManagedInstances(ctx, controllerUUID)
if err != nil {
if err == environs.ErrNoInstances {
return nil
}
providerCommon.HandleCredentialError(err, ctx)
return errors.Trace(err)
}
ids := make([]instance.Id, len(instances))
for i, val := range instances {
ids[i] = val.Id()
}
err = e.StopInstances(ctx, ids...)
if err != nil {
providerCommon.HandleCredentialError(err, ctx)
return errors.Trace(err)
}
logger.Debugf("Cleaning up network resources")
err = e.cleanupNetworksAndSubnets(controllerUUID, "")
if err != nil {
providerCommon.HandleCredentialError(err, ctx)
return errors.Trace(err)
}
return nil
} | go | func (e *Environ) DestroyController(ctx envcontext.ProviderCallContext, controllerUUID string) error {
err := e.Destroy(ctx)
if err != nil {
providerCommon.HandleCredentialError(err, ctx)
logger.Errorf("Failed to destroy environment through controller: %s", errors.Trace(err))
}
instances, err := e.allControllerManagedInstances(ctx, controllerUUID)
if err != nil {
if err == environs.ErrNoInstances {
return nil
}
providerCommon.HandleCredentialError(err, ctx)
return errors.Trace(err)
}
ids := make([]instance.Id, len(instances))
for i, val := range instances {
ids[i] = val.Id()
}
err = e.StopInstances(ctx, ids...)
if err != nil {
providerCommon.HandleCredentialError(err, ctx)
return errors.Trace(err)
}
logger.Debugf("Cleaning up network resources")
err = e.cleanupNetworksAndSubnets(controllerUUID, "")
if err != nil {
providerCommon.HandleCredentialError(err, ctx)
return errors.Trace(err)
}
return nil
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"DestroyController",
"(",
"ctx",
"envcontext",
".",
"ProviderCallContext",
",",
"controllerUUID",
"string",
")",
"error",
"{",
"err",
":=",
"e",
".",
"Destroy",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"providerCommon",
".",
"HandleCredentialError",
"(",
"err",
",",
"ctx",
")",
"\n",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
")",
"\n",
"}",
"\n",
"instances",
",",
"err",
":=",
"e",
".",
"allControllerManagedInstances",
"(",
"ctx",
",",
"controllerUUID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"environs",
".",
"ErrNoInstances",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"providerCommon",
".",
"HandleCredentialError",
"(",
"err",
",",
"ctx",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"ids",
":=",
"make",
"(",
"[",
"]",
"instance",
".",
"Id",
",",
"len",
"(",
"instances",
")",
")",
"\n",
"for",
"i",
",",
"val",
":=",
"range",
"instances",
"{",
"ids",
"[",
"i",
"]",
"=",
"val",
".",
"Id",
"(",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"e",
".",
"StopInstances",
"(",
"ctx",
",",
"ids",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"providerCommon",
".",
"HandleCredentialError",
"(",
"err",
",",
"ctx",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"err",
"=",
"e",
".",
"cleanupNetworksAndSubnets",
"(",
"controllerUUID",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"providerCommon",
".",
"HandleCredentialError",
"(",
"err",
",",
"ctx",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // DestroyController implements environs.Environ. | [
"DestroyController",
"implements",
"environs",
".",
"Environ",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L388-L420 |
5,049 | juju/juju | provider/oci/environ.go | getCloudInitConfig | func (e *Environ) getCloudInitConfig(series string, apiPort int) (cloudinit.CloudConfig, error) {
// TODO (gsamfira): remove this function when the above mention bug is fixed
cloudcfg, err := cloudinit.New(series)
if err != nil {
return nil, errors.Annotate(err, "cannot create cloudinit template")
}
if apiPort == 0 {
return cloudcfg, nil
}
operatingSystem, err := jujuseries.GetOSFromSeries(series)
if err != nil {
return nil, errors.Trace(err)
}
switch operatingSystem {
case os.Ubuntu:
fwCmd := fmt.Sprintf(
"/sbin/iptables -I INPUT -p tcp --dport %d -j ACCEPT", apiPort)
cloudcfg.AddRunCmd(fwCmd)
cloudcfg.AddScripts("/etc/init.d/netfilter-persistent save")
case os.CentOS:
fwCmd := fmt.Sprintf("firewall-cmd --zone=public --add-port=%d/tcp --permanent", apiPort)
cloudcfg.AddRunCmd(fwCmd)
cloudcfg.AddRunCmd("firewall-cmd --reload")
}
return cloudcfg, nil
} | go | func (e *Environ) getCloudInitConfig(series string, apiPort int) (cloudinit.CloudConfig, error) {
// TODO (gsamfira): remove this function when the above mention bug is fixed
cloudcfg, err := cloudinit.New(series)
if err != nil {
return nil, errors.Annotate(err, "cannot create cloudinit template")
}
if apiPort == 0 {
return cloudcfg, nil
}
operatingSystem, err := jujuseries.GetOSFromSeries(series)
if err != nil {
return nil, errors.Trace(err)
}
switch operatingSystem {
case os.Ubuntu:
fwCmd := fmt.Sprintf(
"/sbin/iptables -I INPUT -p tcp --dport %d -j ACCEPT", apiPort)
cloudcfg.AddRunCmd(fwCmd)
cloudcfg.AddScripts("/etc/init.d/netfilter-persistent save")
case os.CentOS:
fwCmd := fmt.Sprintf("firewall-cmd --zone=public --add-port=%d/tcp --permanent", apiPort)
cloudcfg.AddRunCmd(fwCmd)
cloudcfg.AddRunCmd("firewall-cmd --reload")
}
return cloudcfg, nil
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"getCloudInitConfig",
"(",
"series",
"string",
",",
"apiPort",
"int",
")",
"(",
"cloudinit",
".",
"CloudConfig",
",",
"error",
")",
"{",
"// TODO (gsamfira): remove this function when the above mention bug is fixed",
"cloudcfg",
",",
"err",
":=",
"cloudinit",
".",
"New",
"(",
"series",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"apiPort",
"==",
"0",
"{",
"return",
"cloudcfg",
",",
"nil",
"\n",
"}",
"\n\n",
"operatingSystem",
",",
"err",
":=",
"jujuseries",
".",
"GetOSFromSeries",
"(",
"series",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"switch",
"operatingSystem",
"{",
"case",
"os",
".",
"Ubuntu",
":",
"fwCmd",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"apiPort",
")",
"\n",
"cloudcfg",
".",
"AddRunCmd",
"(",
"fwCmd",
")",
"\n",
"cloudcfg",
".",
"AddScripts",
"(",
"\"",
"\"",
")",
"\n",
"case",
"os",
".",
"CentOS",
":",
"fwCmd",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"apiPort",
")",
"\n",
"cloudcfg",
".",
"AddRunCmd",
"(",
"fwCmd",
")",
"\n",
"cloudcfg",
".",
"AddRunCmd",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"cloudcfg",
",",
"nil",
"\n",
"}"
] | // getCloudInitConfig returns a CloudConfig instance. The default oracle images come
// bundled with iptables-persistent on Ubuntu and firewalld on CentOS, which maintains
// a number of iptables firewall rules. We need to at least allow the juju API port for state
// machines. SSH port is allowed by default on linux images. | [
"getCloudInitConfig",
"returns",
"a",
"CloudConfig",
"instance",
".",
"The",
"default",
"oracle",
"images",
"come",
"bundled",
"with",
"iptables",
"-",
"persistent",
"on",
"Ubuntu",
"and",
"firewalld",
"on",
"CentOS",
"which",
"maintains",
"a",
"number",
"of",
"iptables",
"firewall",
"rules",
".",
"We",
"need",
"to",
"at",
"least",
"allow",
"the",
"juju",
"API",
"port",
"for",
"state",
"machines",
".",
"SSH",
"port",
"is",
"allowed",
"by",
"default",
"on",
"linux",
"images",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L431-L458 |
5,050 | juju/juju | provider/oci/environ.go | MaintainInstance | func (e *Environ) MaintainInstance(ctx envcontext.ProviderCallContext, args environs.StartInstanceParams) error {
return nil
} | go | func (e *Environ) MaintainInstance(ctx envcontext.ProviderCallContext, args environs.StartInstanceParams) error {
return nil
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"MaintainInstance",
"(",
"ctx",
"envcontext",
".",
"ProviderCallContext",
",",
"args",
"environs",
".",
"StartInstanceParams",
")",
"error",
"{",
"return",
"nil",
"\n",
"}"
] | // MaintainInstance implements environs.InstanceBroker. | [
"MaintainInstance",
"implements",
"environs",
".",
"InstanceBroker",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L756-L758 |
5,051 | juju/juju | provider/oci/environ.go | Config | func (e *Environ) Config() *config.Config {
e.ecfgMutex.Lock()
defer e.ecfgMutex.Unlock()
if e.ecfgObj == nil {
return nil
}
return e.ecfgObj.Config
} | go | func (e *Environ) Config() *config.Config {
e.ecfgMutex.Lock()
defer e.ecfgMutex.Unlock()
if e.ecfgObj == nil {
return nil
}
return e.ecfgObj.Config
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"Config",
"(",
")",
"*",
"config",
".",
"Config",
"{",
"e",
".",
"ecfgMutex",
".",
"Lock",
"(",
")",
"\n",
"defer",
"e",
".",
"ecfgMutex",
".",
"Unlock",
"(",
")",
"\n",
"if",
"e",
".",
"ecfgObj",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"e",
".",
"ecfgObj",
".",
"Config",
"\n",
"}"
] | // Config implements environs.ConfigGetter. | [
"Config",
"implements",
"environs",
".",
"ConfigGetter",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L761-L768 |
5,052 | juju/juju | provider/oci/environ.go | InstanceTypes | func (e *Environ) InstanceTypes(envcontext.ProviderCallContext, constraints.Value) (instances.InstanceTypesWithCostMetadata, error) {
return instances.InstanceTypesWithCostMetadata{}, errors.NotImplementedf("InstanceTypes")
} | go | func (e *Environ) InstanceTypes(envcontext.ProviderCallContext, constraints.Value) (instances.InstanceTypesWithCostMetadata, error) {
return instances.InstanceTypesWithCostMetadata{}, errors.NotImplementedf("InstanceTypes")
} | [
"func",
"(",
"e",
"*",
"Environ",
")",
"InstanceTypes",
"(",
"envcontext",
".",
"ProviderCallContext",
",",
"constraints",
".",
"Value",
")",
"(",
"instances",
".",
"InstanceTypesWithCostMetadata",
",",
"error",
")",
"{",
"return",
"instances",
".",
"InstanceTypesWithCostMetadata",
"{",
"}",
",",
"errors",
".",
"NotImplementedf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // InstanceTypes implements environs.InstancePrechecker. | [
"InstanceTypes",
"implements",
"environs",
".",
"InstancePrechecker",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/oci/environ.go#L776-L778 |
5,053 | juju/juju | core/instance/hardwarecharacteristics.go | MustParseHardware | func MustParseHardware(args ...string) HardwareCharacteristics {
hc, err := ParseHardware(args...)
if err != nil {
panic(err)
}
return hc
} | go | func MustParseHardware(args ...string) HardwareCharacteristics {
hc, err := ParseHardware(args...)
if err != nil {
panic(err)
}
return hc
} | [
"func",
"MustParseHardware",
"(",
"args",
"...",
"string",
")",
"HardwareCharacteristics",
"{",
"hc",
",",
"err",
":=",
"ParseHardware",
"(",
"args",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"hc",
"\n",
"}"
] | // MustParseHardware constructs a HardwareCharacteristics from the supplied arguments,
// as Parse, but panics on failure. | [
"MustParseHardware",
"constructs",
"a",
"HardwareCharacteristics",
"from",
"the",
"supplied",
"arguments",
"as",
"Parse",
"but",
"panics",
"on",
"failure",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/instance/hardwarecharacteristics.go#L74-L80 |
5,054 | juju/juju | core/instance/hardwarecharacteristics.go | ParseHardware | func ParseHardware(args ...string) (HardwareCharacteristics, error) {
hc := HardwareCharacteristics{}
for _, arg := range args {
raws := strings.Split(strings.TrimSpace(arg), " ")
for _, raw := range raws {
if raw == "" {
continue
}
if err := hc.setRaw(raw); err != nil {
return HardwareCharacteristics{}, err
}
}
}
return hc, nil
} | go | func ParseHardware(args ...string) (HardwareCharacteristics, error) {
hc := HardwareCharacteristics{}
for _, arg := range args {
raws := strings.Split(strings.TrimSpace(arg), " ")
for _, raw := range raws {
if raw == "" {
continue
}
if err := hc.setRaw(raw); err != nil {
return HardwareCharacteristics{}, err
}
}
}
return hc, nil
} | [
"func",
"ParseHardware",
"(",
"args",
"...",
"string",
")",
"(",
"HardwareCharacteristics",
",",
"error",
")",
"{",
"hc",
":=",
"HardwareCharacteristics",
"{",
"}",
"\n",
"for",
"_",
",",
"arg",
":=",
"range",
"args",
"{",
"raws",
":=",
"strings",
".",
"Split",
"(",
"strings",
".",
"TrimSpace",
"(",
"arg",
")",
",",
"\"",
"\"",
")",
"\n",
"for",
"_",
",",
"raw",
":=",
"range",
"raws",
"{",
"if",
"raw",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":=",
"hc",
".",
"setRaw",
"(",
"raw",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"HardwareCharacteristics",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"hc",
",",
"nil",
"\n",
"}"
] | // ParseHardware constructs a HardwareCharacteristics from the supplied arguments,
// each of which must contain only spaces and name=value pairs. If any
// name is specified more than once, an error is returned. | [
"ParseHardware",
"constructs",
"a",
"HardwareCharacteristics",
"from",
"the",
"supplied",
"arguments",
"each",
"of",
"which",
"must",
"contain",
"only",
"spaces",
"and",
"name",
"=",
"value",
"pairs",
".",
"If",
"any",
"name",
"is",
"specified",
"more",
"than",
"once",
"an",
"error",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/instance/hardwarecharacteristics.go#L85-L99 |
5,055 | juju/juju | core/instance/hardwarecharacteristics.go | parseTags | func parseTags(s string) *[]string {
if s == "" {
return &[]string{}
}
tags := strings.Split(s, ",")
return &tags
} | go | func parseTags(s string) *[]string {
if s == "" {
return &[]string{}
}
tags := strings.Split(s, ",")
return &tags
} | [
"func",
"parseTags",
"(",
"s",
"string",
")",
"*",
"[",
"]",
"string",
"{",
"if",
"s",
"==",
"\"",
"\"",
"{",
"return",
"&",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n",
"tags",
":=",
"strings",
".",
"Split",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"return",
"&",
"tags",
"\n",
"}"
] | // parseTags returns the tags in the value s | [
"parseTags",
"returns",
"the",
"tags",
"in",
"the",
"value",
"s"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/core/instance/hardwarecharacteristics.go#L207-L213 |
5,056 | juju/juju | worker/raft/raftutil/logging.go | Write | func (w *LoggoWriter) Write(p []byte) (int, error) {
w.Logger.Logf(w.Level, "%s", p[:len(p)-1]) // omit trailing newline
return len(p), nil
} | go | func (w *LoggoWriter) Write(p []byte) (int, error) {
w.Logger.Logf(w.Level, "%s", p[:len(p)-1]) // omit trailing newline
return len(p), nil
} | [
"func",
"(",
"w",
"*",
"LoggoWriter",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"w",
".",
"Logger",
".",
"Logf",
"(",
"w",
".",
"Level",
",",
"\"",
"\"",
",",
"p",
"[",
":",
"len",
"(",
"p",
")",
"-",
"1",
"]",
")",
"// omit trailing newline",
"\n",
"return",
"len",
"(",
"p",
")",
",",
"nil",
"\n",
"}"
] | // Write is part of the io.Writer interface. | [
"Write",
"is",
"part",
"of",
"the",
"io",
".",
"Writer",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/raft/raftutil/logging.go#L22-L25 |
5,057 | juju/juju | provider/dummy/environs.go | SampleCloudSpec | func SampleCloudSpec() environs.CloudSpec {
cred := cloud.NewCredential(cloud.UserPassAuthType, map[string]string{"username": "dummy", "password": "secret"})
return environs.CloudSpec{
Type: "dummy",
Name: "dummy",
Endpoint: "dummy-endpoint",
IdentityEndpoint: "dummy-identity-endpoint",
Region: "dummy-region",
StorageEndpoint: "dummy-storage-endpoint",
Credential: &cred,
}
} | go | func SampleCloudSpec() environs.CloudSpec {
cred := cloud.NewCredential(cloud.UserPassAuthType, map[string]string{"username": "dummy", "password": "secret"})
return environs.CloudSpec{
Type: "dummy",
Name: "dummy",
Endpoint: "dummy-endpoint",
IdentityEndpoint: "dummy-identity-endpoint",
Region: "dummy-region",
StorageEndpoint: "dummy-storage-endpoint",
Credential: &cred,
}
} | [
"func",
"SampleCloudSpec",
"(",
")",
"environs",
".",
"CloudSpec",
"{",
"cred",
":=",
"cloud",
".",
"NewCredential",
"(",
"cloud",
".",
"UserPassAuthType",
",",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
",",
"\"",
"\"",
":",
"\"",
"\"",
"}",
")",
"\n",
"return",
"environs",
".",
"CloudSpec",
"{",
"Type",
":",
"\"",
"\"",
",",
"Name",
":",
"\"",
"\"",
",",
"Endpoint",
":",
"\"",
"\"",
",",
"IdentityEndpoint",
":",
"\"",
"\"",
",",
"Region",
":",
"\"",
"\"",
",",
"StorageEndpoint",
":",
"\"",
"\"",
",",
"Credential",
":",
"&",
"cred",
",",
"}",
"\n",
"}"
] | // SampleCloudSpec returns an environs.CloudSpec that can be used to
// open a dummy Environ. | [
"SampleCloudSpec",
"returns",
"an",
"environs",
".",
"CloudSpec",
"that",
"can",
"be",
"used",
"to",
"open",
"a",
"dummy",
"Environ",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L98-L109 |
5,058 | juju/juju | provider/dummy/environs.go | mongoInfo | func mongoInfo() mongo.MongoInfo {
if gitjujutesting.MgoServer.Addr() == "" {
panic("dummy environ state tests must be run with MgoTestPackage")
}
mongoPort := strconv.Itoa(gitjujutesting.MgoServer.Port())
addrs := []string{net.JoinHostPort("localhost", mongoPort)}
return mongo.MongoInfo{
Info: mongo.Info{
Addrs: addrs,
CACert: testing.CACert,
DisableTLS: !gitjujutesting.MgoServer.SSLEnabled(),
},
}
} | go | func mongoInfo() mongo.MongoInfo {
if gitjujutesting.MgoServer.Addr() == "" {
panic("dummy environ state tests must be run with MgoTestPackage")
}
mongoPort := strconv.Itoa(gitjujutesting.MgoServer.Port())
addrs := []string{net.JoinHostPort("localhost", mongoPort)}
return mongo.MongoInfo{
Info: mongo.Info{
Addrs: addrs,
CACert: testing.CACert,
DisableTLS: !gitjujutesting.MgoServer.SSLEnabled(),
},
}
} | [
"func",
"mongoInfo",
"(",
")",
"mongo",
".",
"MongoInfo",
"{",
"if",
"gitjujutesting",
".",
"MgoServer",
".",
"Addr",
"(",
")",
"==",
"\"",
"\"",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"mongoPort",
":=",
"strconv",
".",
"Itoa",
"(",
"gitjujutesting",
".",
"MgoServer",
".",
"Port",
"(",
")",
")",
"\n",
"addrs",
":=",
"[",
"]",
"string",
"{",
"net",
".",
"JoinHostPort",
"(",
"\"",
"\"",
",",
"mongoPort",
")",
"}",
"\n",
"return",
"mongo",
".",
"MongoInfo",
"{",
"Info",
":",
"mongo",
".",
"Info",
"{",
"Addrs",
":",
"addrs",
",",
"CACert",
":",
"testing",
".",
"CACert",
",",
"DisableTLS",
":",
"!",
"gitjujutesting",
".",
"MgoServer",
".",
"SSLEnabled",
"(",
")",
",",
"}",
",",
"}",
"\n",
"}"
] | // mongoInfo returns a mongo.MongoInfo which allows clients to connect to the
// shared dummy state, if it exists. | [
"mongoInfo",
"returns",
"a",
"mongo",
".",
"MongoInfo",
"which",
"allows",
"clients",
"to",
"connect",
"to",
"the",
"shared",
"dummy",
"state",
"if",
"it",
"exists",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L141-L154 |
5,059 | juju/juju | provider/dummy/environs.go | Reset | func Reset(c *gc.C) {
logger.Infof("reset model")
dummy.mu.Lock()
dummy.ops = discardOperations
oldState := dummy.state
dummy.controllerState = nil
dummy.state = make(map[string]*environState)
dummy.newStatePolicy = stateenvirons.GetNewPolicyFunc()
dummy.supportsSpaces = true
dummy.supportsSpaceDiscovery = false
dummy.mu.Unlock()
// NOTE(axw) we must destroy the old states without holding
// the provider lock, or we risk deadlocking. Destroying
// state involves closing the embedded API server, which
// may require waiting on RPC calls that interact with the
// EnvironProvider (e.g. EnvironProvider.Open).
for _, s := range oldState {
if s.httpServer != nil {
logger.Debugf("closing httpServer")
s.httpServer.Close()
}
s.destroy()
}
if mongoAlive() {
err := retry.Call(retry.CallArgs{
Func: gitjujutesting.MgoServer.Reset,
// Only interested in retrying the intermittent
// 'unexpected message'.
IsFatalError: func(err error) bool {
return !strings.HasSuffix(err.Error(), "unexpected message")
},
Delay: time.Millisecond,
Clock: clock.WallClock,
Attempts: 5,
})
c.Assert(err, jc.ErrorIsNil)
}
} | go | func Reset(c *gc.C) {
logger.Infof("reset model")
dummy.mu.Lock()
dummy.ops = discardOperations
oldState := dummy.state
dummy.controllerState = nil
dummy.state = make(map[string]*environState)
dummy.newStatePolicy = stateenvirons.GetNewPolicyFunc()
dummy.supportsSpaces = true
dummy.supportsSpaceDiscovery = false
dummy.mu.Unlock()
// NOTE(axw) we must destroy the old states without holding
// the provider lock, or we risk deadlocking. Destroying
// state involves closing the embedded API server, which
// may require waiting on RPC calls that interact with the
// EnvironProvider (e.g. EnvironProvider.Open).
for _, s := range oldState {
if s.httpServer != nil {
logger.Debugf("closing httpServer")
s.httpServer.Close()
}
s.destroy()
}
if mongoAlive() {
err := retry.Call(retry.CallArgs{
Func: gitjujutesting.MgoServer.Reset,
// Only interested in retrying the intermittent
// 'unexpected message'.
IsFatalError: func(err error) bool {
return !strings.HasSuffix(err.Error(), "unexpected message")
},
Delay: time.Millisecond,
Clock: clock.WallClock,
Attempts: 5,
})
c.Assert(err, jc.ErrorIsNil)
}
} | [
"func",
"Reset",
"(",
"c",
"*",
"gc",
".",
"C",
")",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
")",
"\n",
"dummy",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"dummy",
".",
"ops",
"=",
"discardOperations",
"\n",
"oldState",
":=",
"dummy",
".",
"state",
"\n",
"dummy",
".",
"controllerState",
"=",
"nil",
"\n",
"dummy",
".",
"state",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"environState",
")",
"\n",
"dummy",
".",
"newStatePolicy",
"=",
"stateenvirons",
".",
"GetNewPolicyFunc",
"(",
")",
"\n",
"dummy",
".",
"supportsSpaces",
"=",
"true",
"\n",
"dummy",
".",
"supportsSpaceDiscovery",
"=",
"false",
"\n",
"dummy",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"// NOTE(axw) we must destroy the old states without holding",
"// the provider lock, or we risk deadlocking. Destroying",
"// state involves closing the embedded API server, which",
"// may require waiting on RPC calls that interact with the",
"// EnvironProvider (e.g. EnvironProvider.Open).",
"for",
"_",
",",
"s",
":=",
"range",
"oldState",
"{",
"if",
"s",
".",
"httpServer",
"!=",
"nil",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"s",
".",
"httpServer",
".",
"Close",
"(",
")",
"\n",
"}",
"\n",
"s",
".",
"destroy",
"(",
")",
"\n",
"}",
"\n",
"if",
"mongoAlive",
"(",
")",
"{",
"err",
":=",
"retry",
".",
"Call",
"(",
"retry",
".",
"CallArgs",
"{",
"Func",
":",
"gitjujutesting",
".",
"MgoServer",
".",
"Reset",
",",
"// Only interested in retrying the intermittent",
"// 'unexpected message'.",
"IsFatalError",
":",
"func",
"(",
"err",
"error",
")",
"bool",
"{",
"return",
"!",
"strings",
".",
"HasSuffix",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"}",
",",
"Delay",
":",
"time",
".",
"Millisecond",
",",
"Clock",
":",
"clock",
".",
"WallClock",
",",
"Attempts",
":",
"5",
",",
"}",
")",
"\n",
"c",
".",
"Assert",
"(",
"err",
",",
"jc",
".",
"ErrorIsNil",
")",
"\n",
"}",
"\n",
"}"
] | // Reset resets the entire dummy environment and forgets any registered
// operation listener. All opened environments after Reset will share
// the same underlying state. | [
"Reset",
"resets",
"the",
"entire",
"dummy",
"environment",
"and",
"forgets",
"any",
"registered",
"operation",
"listener",
".",
"All",
"opened",
"environments",
"after",
"Reset",
"will",
"share",
"the",
"same",
"underlying",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L319-L357 |
5,060 | juju/juju | provider/dummy/environs.go | GetStateInAPIServer | func (e *environ) GetStateInAPIServer() *state.State {
st, err := e.state()
if err != nil {
panic(err)
}
return st.apiState
} | go | func (e *environ) GetStateInAPIServer() *state.State {
st, err := e.state()
if err != nil {
panic(err)
}
return st.apiState
} | [
"func",
"(",
"e",
"*",
"environ",
")",
"GetStateInAPIServer",
"(",
")",
"*",
"state",
".",
"State",
"{",
"st",
",",
"err",
":=",
"e",
".",
"state",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"st",
".",
"apiState",
"\n",
"}"
] | // GetStateInAPIServer returns the state connection used by the API server
// This is so code in the test suite can trigger Syncs, etc that the API server
// will see, which will then trigger API watchers, etc. | [
"GetStateInAPIServer",
"returns",
"the",
"state",
"connection",
"used",
"by",
"the",
"API",
"server",
"This",
"is",
"so",
"code",
"in",
"the",
"test",
"suite",
"can",
"trigger",
"Syncs",
"etc",
"that",
"the",
"API",
"server",
"will",
"see",
"which",
"will",
"then",
"trigger",
"API",
"watchers",
"etc",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L434-L440 |
5,061 | juju/juju | provider/dummy/environs.go | GetStatePoolInAPIServer | func (e *environ) GetStatePoolInAPIServer() *state.StatePool {
st, err := e.state()
if err != nil {
panic(err)
}
return st.apiStatePool
} | go | func (e *environ) GetStatePoolInAPIServer() *state.StatePool {
st, err := e.state()
if err != nil {
panic(err)
}
return st.apiStatePool
} | [
"func",
"(",
"e",
"*",
"environ",
")",
"GetStatePoolInAPIServer",
"(",
")",
"*",
"state",
".",
"StatePool",
"{",
"st",
",",
"err",
":=",
"e",
".",
"state",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"st",
".",
"apiStatePool",
"\n",
"}"
] | // GetStatePoolInAPIServer returns the StatePool used by the API
// server. As for GetStatePoolInAPIServer, this is so code in the
// test suite can trigger Syncs etc. | [
"GetStatePoolInAPIServer",
"returns",
"the",
"StatePool",
"used",
"by",
"the",
"API",
"server",
".",
"As",
"for",
"GetStatePoolInAPIServer",
"this",
"is",
"so",
"code",
"in",
"the",
"test",
"suite",
"can",
"trigger",
"Syncs",
"etc",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L445-L451 |
5,062 | juju/juju | provider/dummy/environs.go | GetHubInAPIServer | func (e *environ) GetHubInAPIServer() *pubsub.StructuredHub {
st, err := e.state()
if err != nil {
panic(err)
}
return st.hub
} | go | func (e *environ) GetHubInAPIServer() *pubsub.StructuredHub {
st, err := e.state()
if err != nil {
panic(err)
}
return st.hub
} | [
"func",
"(",
"e",
"*",
"environ",
")",
"GetHubInAPIServer",
"(",
")",
"*",
"pubsub",
".",
"StructuredHub",
"{",
"st",
",",
"err",
":=",
"e",
".",
"state",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"st",
".",
"hub",
"\n",
"}"
] | // GetHubInAPIServer returns the central hub used by the API server. | [
"GetHubInAPIServer",
"returns",
"the",
"central",
"hub",
"used",
"by",
"the",
"API",
"server",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L454-L460 |
5,063 | juju/juju | provider/dummy/environs.go | GetLeaseManagerInAPIServer | func (e *environ) GetLeaseManagerInAPIServer() corelease.Manager {
st, err := e.state()
if err != nil {
panic(err)
}
return st.leaseManager
} | go | func (e *environ) GetLeaseManagerInAPIServer() corelease.Manager {
st, err := e.state()
if err != nil {
panic(err)
}
return st.leaseManager
} | [
"func",
"(",
"e",
"*",
"environ",
")",
"GetLeaseManagerInAPIServer",
"(",
")",
"corelease",
".",
"Manager",
"{",
"st",
",",
"err",
":=",
"e",
".",
"state",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"st",
".",
"leaseManager",
"\n",
"}"
] | // GetLeaseManagerInAPIServer returns the channel used to update the
// cache.Controller used by the API server | [
"GetLeaseManagerInAPIServer",
"returns",
"the",
"channel",
"used",
"to",
"update",
"the",
"cache",
".",
"Controller",
"used",
"by",
"the",
"API",
"server"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L464-L470 |
5,064 | juju/juju | provider/dummy/environs.go | GetController | func (e *environ) GetController() *cache.Controller {
st, err := e.state()
if err != nil {
panic(err)
}
return st.controller
} | go | func (e *environ) GetController() *cache.Controller {
st, err := e.state()
if err != nil {
panic(err)
}
return st.controller
} | [
"func",
"(",
"e",
"*",
"environ",
")",
"GetController",
"(",
")",
"*",
"cache",
".",
"Controller",
"{",
"st",
",",
"err",
":=",
"e",
".",
"state",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"st",
".",
"controller",
"\n",
"}"
] | // GetController returns the cache.Controller used by the API server. | [
"GetController",
"returns",
"the",
"cache",
".",
"Controller",
"used",
"by",
"the",
"API",
"server",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L473-L479 |
5,065 | juju/juju | provider/dummy/environs.go | newState | func newState(name string, ops chan<- Operation, newStatePolicy state.NewPolicyFunc) *environState {
buf := make([]byte, 8192)
buf = buf[:runtime.Stack(buf, false)]
s := &environState{
name: name,
ops: ops,
newStatePolicy: newStatePolicy,
insts: make(map[instance.Id]*dummyInstance),
creator: string(buf),
}
return s
} | go | func newState(name string, ops chan<- Operation, newStatePolicy state.NewPolicyFunc) *environState {
buf := make([]byte, 8192)
buf = buf[:runtime.Stack(buf, false)]
s := &environState{
name: name,
ops: ops,
newStatePolicy: newStatePolicy,
insts: make(map[instance.Id]*dummyInstance),
creator: string(buf),
}
return s
} | [
"func",
"newState",
"(",
"name",
"string",
",",
"ops",
"chan",
"<-",
"Operation",
",",
"newStatePolicy",
"state",
".",
"NewPolicyFunc",
")",
"*",
"environState",
"{",
"buf",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"8192",
")",
"\n",
"buf",
"=",
"buf",
"[",
":",
"runtime",
".",
"Stack",
"(",
"buf",
",",
"false",
")",
"]",
"\n",
"s",
":=",
"&",
"environState",
"{",
"name",
":",
"name",
",",
"ops",
":",
"ops",
",",
"newStatePolicy",
":",
"newStatePolicy",
",",
"insts",
":",
"make",
"(",
"map",
"[",
"instance",
".",
"Id",
"]",
"*",
"dummyInstance",
")",
",",
"creator",
":",
"string",
"(",
"buf",
")",
",",
"}",
"\n",
"return",
"s",
"\n",
"}"
] | // newState creates the state for a new environment with the given name. | [
"newState",
"creates",
"the",
"state",
"for",
"a",
"new",
"environment",
"with",
"the",
"given",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L482-L493 |
5,066 | juju/juju | provider/dummy/environs.go | listenAPI | func (s *environState) listenAPI() int {
certPool, err := api.CreateCertPool(testing.CACert)
if err != nil {
panic(err)
}
tlsConfig := api.NewTLSConfig(certPool)
tlsConfig.ServerName = "juju-apiserver"
tlsConfig.Certificates = []tls.Certificate{*testing.ServerTLSCert}
s.mux = apiserverhttp.NewMux()
s.httpServer = httptest.NewUnstartedServer(s.mux)
s.httpServer.TLS = tlsConfig
return s.httpServer.Listener.Addr().(*net.TCPAddr).Port
} | go | func (s *environState) listenAPI() int {
certPool, err := api.CreateCertPool(testing.CACert)
if err != nil {
panic(err)
}
tlsConfig := api.NewTLSConfig(certPool)
tlsConfig.ServerName = "juju-apiserver"
tlsConfig.Certificates = []tls.Certificate{*testing.ServerTLSCert}
s.mux = apiserverhttp.NewMux()
s.httpServer = httptest.NewUnstartedServer(s.mux)
s.httpServer.TLS = tlsConfig
return s.httpServer.Listener.Addr().(*net.TCPAddr).Port
} | [
"func",
"(",
"s",
"*",
"environState",
")",
"listenAPI",
"(",
")",
"int",
"{",
"certPool",
",",
"err",
":=",
"api",
".",
"CreateCertPool",
"(",
"testing",
".",
"CACert",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"tlsConfig",
":=",
"api",
".",
"NewTLSConfig",
"(",
"certPool",
")",
"\n",
"tlsConfig",
".",
"ServerName",
"=",
"\"",
"\"",
"\n",
"tlsConfig",
".",
"Certificates",
"=",
"[",
"]",
"tls",
".",
"Certificate",
"{",
"*",
"testing",
".",
"ServerTLSCert",
"}",
"\n",
"s",
".",
"mux",
"=",
"apiserverhttp",
".",
"NewMux",
"(",
")",
"\n",
"s",
".",
"httpServer",
"=",
"httptest",
".",
"NewUnstartedServer",
"(",
"s",
".",
"mux",
")",
"\n",
"s",
".",
"httpServer",
".",
"TLS",
"=",
"tlsConfig",
"\n",
"return",
"s",
".",
"httpServer",
".",
"Listener",
".",
"Addr",
"(",
")",
".",
"(",
"*",
"net",
".",
"TCPAddr",
")",
".",
"Port",
"\n",
"}"
] | // listenAPI starts an HTTP server listening for API connections. | [
"listenAPI",
"starts",
"an",
"HTTP",
"server",
"listening",
"for",
"API",
"connections",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L496-L508 |
5,067 | juju/juju | provider/dummy/environs.go | SetSupportsSpaces | func SetSupportsSpaces(supports bool) bool {
dummy.mu.Lock()
defer dummy.mu.Unlock()
current := dummy.supportsSpaces
dummy.supportsSpaces = supports
return current
} | go | func SetSupportsSpaces(supports bool) bool {
dummy.mu.Lock()
defer dummy.mu.Unlock()
current := dummy.supportsSpaces
dummy.supportsSpaces = supports
return current
} | [
"func",
"SetSupportsSpaces",
"(",
"supports",
"bool",
")",
"bool",
"{",
"dummy",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"dummy",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"current",
":=",
"dummy",
".",
"supportsSpaces",
"\n",
"dummy",
".",
"supportsSpaces",
"=",
"supports",
"\n",
"return",
"current",
"\n",
"}"
] | // SetSupportsSpaces allows to enable and disable SupportsSpaces for tests. | [
"SetSupportsSpaces",
"allows",
"to",
"enable",
"and",
"disable",
"SupportsSpaces",
"for",
"tests",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L511-L517 |
5,068 | juju/juju | provider/dummy/environs.go | SetSupportsSpaceDiscovery | func SetSupportsSpaceDiscovery(supports bool) bool {
dummy.mu.Lock()
defer dummy.mu.Unlock()
current := dummy.supportsSpaceDiscovery
dummy.supportsSpaceDiscovery = supports
return current
} | go | func SetSupportsSpaceDiscovery(supports bool) bool {
dummy.mu.Lock()
defer dummy.mu.Unlock()
current := dummy.supportsSpaceDiscovery
dummy.supportsSpaceDiscovery = supports
return current
} | [
"func",
"SetSupportsSpaceDiscovery",
"(",
"supports",
"bool",
")",
"bool",
"{",
"dummy",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"dummy",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"current",
":=",
"dummy",
".",
"supportsSpaceDiscovery",
"\n",
"dummy",
".",
"supportsSpaceDiscovery",
"=",
"supports",
"\n",
"return",
"current",
"\n",
"}"
] | // SetSupportsSpaceDiscovery allows to enable and disable
// SupportsSpaceDiscovery for tests. | [
"SetSupportsSpaceDiscovery",
"allows",
"to",
"enable",
"and",
"disable",
"SupportsSpaceDiscovery",
"for",
"tests",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L521-L527 |
5,069 | juju/juju | provider/dummy/environs.go | PrecheckInstance | func (*environ) PrecheckInstance(ctx context.ProviderCallContext, args environs.PrecheckInstanceParams) error {
if args.Placement != "" && args.Placement != "valid" {
return fmt.Errorf("%s placement is invalid", args.Placement)
}
return nil
} | go | func (*environ) PrecheckInstance(ctx context.ProviderCallContext, args environs.PrecheckInstanceParams) error {
if args.Placement != "" && args.Placement != "valid" {
return fmt.Errorf("%s placement is invalid", args.Placement)
}
return nil
} | [
"func",
"(",
"*",
"environ",
")",
"PrecheckInstance",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"args",
"environs",
".",
"PrecheckInstanceParams",
")",
"error",
"{",
"if",
"args",
".",
"Placement",
"!=",
"\"",
"\"",
"&&",
"args",
".",
"Placement",
"!=",
"\"",
"\"",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"args",
".",
"Placement",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // PrecheckInstance is specified in the environs.InstancePrechecker interface. | [
"PrecheckInstance",
"is",
"specified",
"in",
"the",
"environs",
".",
"InstancePrechecker",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L737-L742 |
5,070 | juju/juju | provider/dummy/environs.go | SupportsSpaceDiscovery | func (env *environ) SupportsSpaceDiscovery(ctx context.ProviderCallContext) (bool, error) {
if err := env.checkBroken("SupportsSpaceDiscovery"); err != nil {
return false, err
}
dummy.mu.Lock()
defer dummy.mu.Unlock()
if !dummy.supportsSpaceDiscovery {
return false, nil
}
return true, nil
} | go | func (env *environ) SupportsSpaceDiscovery(ctx context.ProviderCallContext) (bool, error) {
if err := env.checkBroken("SupportsSpaceDiscovery"); err != nil {
return false, err
}
dummy.mu.Lock()
defer dummy.mu.Unlock()
if !dummy.supportsSpaceDiscovery {
return false, nil
}
return true, nil
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"SupportsSpaceDiscovery",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"err",
":=",
"env",
".",
"checkBroken",
"(",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"dummy",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"dummy",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"if",
"!",
"dummy",
".",
"supportsSpaceDiscovery",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // SupportsSpaceDiscovery is specified on environs.Networking. | [
"SupportsSpaceDiscovery",
"is",
"specified",
"on",
"environs",
".",
"Networking",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L1353-L1363 |
5,071 | juju/juju | provider/dummy/environs.go | Spaces | func (env *environ) Spaces(ctx context.ProviderCallContext) ([]network.SpaceInfo, error) {
if err := env.checkBroken("Spaces"); err != nil {
return []network.SpaceInfo{}, err
}
return []network.SpaceInfo{{
Name: "foo",
ProviderId: network.Id("0"),
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("1"),
AvailabilityZones: []string{"zone1"},
}, {
ProviderId: network.Id("2"),
AvailabilityZones: []string{"zone1"},
}}}, {
Name: "Another Foo 99!",
ProviderId: "1",
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("3"),
AvailabilityZones: []string{"zone1"},
}}}, {
Name: "foo-",
ProviderId: "2",
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("4"),
AvailabilityZones: []string{"zone1"},
}}}, {
Name: "---",
ProviderId: "3",
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("5"),
AvailabilityZones: []string{"zone1"},
}}}}, nil
} | go | func (env *environ) Spaces(ctx context.ProviderCallContext) ([]network.SpaceInfo, error) {
if err := env.checkBroken("Spaces"); err != nil {
return []network.SpaceInfo{}, err
}
return []network.SpaceInfo{{
Name: "foo",
ProviderId: network.Id("0"),
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("1"),
AvailabilityZones: []string{"zone1"},
}, {
ProviderId: network.Id("2"),
AvailabilityZones: []string{"zone1"},
}}}, {
Name: "Another Foo 99!",
ProviderId: "1",
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("3"),
AvailabilityZones: []string{"zone1"},
}}}, {
Name: "foo-",
ProviderId: "2",
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("4"),
AvailabilityZones: []string{"zone1"},
}}}, {
Name: "---",
ProviderId: "3",
Subnets: []network.SubnetInfo{{
ProviderId: network.Id("5"),
AvailabilityZones: []string{"zone1"},
}}}}, nil
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"Spaces",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"(",
"[",
"]",
"network",
".",
"SpaceInfo",
",",
"error",
")",
"{",
"if",
"err",
":=",
"env",
".",
"checkBroken",
"(",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"[",
"]",
"network",
".",
"SpaceInfo",
"{",
"}",
",",
"err",
"\n",
"}",
"\n",
"return",
"[",
"]",
"network",
".",
"SpaceInfo",
"{",
"{",
"Name",
":",
"\"",
"\"",
",",
"ProviderId",
":",
"network",
".",
"Id",
"(",
"\"",
"\"",
")",
",",
"Subnets",
":",
"[",
"]",
"network",
".",
"SubnetInfo",
"{",
"{",
"ProviderId",
":",
"network",
".",
"Id",
"(",
"\"",
"\"",
")",
",",
"AvailabilityZones",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
",",
"{",
"ProviderId",
":",
"network",
".",
"Id",
"(",
"\"",
"\"",
")",
",",
"AvailabilityZones",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
"}",
"}",
",",
"{",
"Name",
":",
"\"",
"\"",
",",
"ProviderId",
":",
"\"",
"\"",
",",
"Subnets",
":",
"[",
"]",
"network",
".",
"SubnetInfo",
"{",
"{",
"ProviderId",
":",
"network",
".",
"Id",
"(",
"\"",
"\"",
")",
",",
"AvailabilityZones",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
"}",
"}",
",",
"{",
"Name",
":",
"\"",
"\"",
",",
"ProviderId",
":",
"\"",
"\"",
",",
"Subnets",
":",
"[",
"]",
"network",
".",
"SubnetInfo",
"{",
"{",
"ProviderId",
":",
"network",
".",
"Id",
"(",
"\"",
"\"",
")",
",",
"AvailabilityZones",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
"}",
"}",
",",
"{",
"Name",
":",
"\"",
"\"",
",",
"ProviderId",
":",
"\"",
"\"",
",",
"Subnets",
":",
"[",
"]",
"network",
".",
"SubnetInfo",
"{",
"{",
"ProviderId",
":",
"network",
".",
"Id",
"(",
"\"",
"\"",
")",
",",
"AvailabilityZones",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
"}",
"}",
"}",
",",
"nil",
"\n",
"}"
] | // Spaces is specified on environs.Networking. | [
"Spaces",
"is",
"specified",
"on",
"environs",
".",
"Networking",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L1371-L1403 |
5,072 | juju/juju | provider/dummy/environs.go | AvailabilityZones | func (env *environ) AvailabilityZones(ctx context.ProviderCallContext) ([]common.AvailabilityZone, error) {
// TODO(dimitern): Fix this properly.
return []common.AvailabilityZone{
azShim{"zone1", true},
azShim{"zone2", false},
azShim{"zone3", true},
azShim{"zone4", true},
}, nil
} | go | func (env *environ) AvailabilityZones(ctx context.ProviderCallContext) ([]common.AvailabilityZone, error) {
// TODO(dimitern): Fix this properly.
return []common.AvailabilityZone{
azShim{"zone1", true},
azShim{"zone2", false},
azShim{"zone3", true},
azShim{"zone4", true},
}, nil
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"AvailabilityZones",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
")",
"(",
"[",
"]",
"common",
".",
"AvailabilityZone",
",",
"error",
")",
"{",
"// TODO(dimitern): Fix this properly.",
"return",
"[",
"]",
"common",
".",
"AvailabilityZone",
"{",
"azShim",
"{",
"\"",
"\"",
",",
"true",
"}",
",",
"azShim",
"{",
"\"",
"\"",
",",
"false",
"}",
",",
"azShim",
"{",
"\"",
"\"",
",",
"true",
"}",
",",
"azShim",
"{",
"\"",
"\"",
",",
"true",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // AvailabilityZones implements environs.ZonedEnviron. | [
"AvailabilityZones",
"implements",
"environs",
".",
"ZonedEnviron",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L1467-L1475 |
5,073 | juju/juju | provider/dummy/environs.go | InstanceAvailabilityZoneNames | func (env *environ) InstanceAvailabilityZoneNames(ctx context.ProviderCallContext, ids []instance.Id) ([]string, error) {
if err := env.checkBroken("InstanceAvailabilityZoneNames"); err != nil {
return nil, errors.NotSupportedf("instance availability zones")
}
availabilityZones, err := env.AvailabilityZones(ctx)
if err != nil {
return nil, err
}
azMaxIndex := len(availabilityZones) - 1
azIndex := 0
returnValue := make([]string, len(ids))
for i := range ids {
if availabilityZones[azIndex].Available() {
returnValue[i] = availabilityZones[azIndex].Name()
} else {
// Based on knowledge of how the AZs are setup above
// in AvailabilityZones()
azIndex += 1
returnValue[i] = availabilityZones[azIndex].Name()
}
azIndex += 1
if azIndex == azMaxIndex {
azIndex = 0
}
}
return returnValue, nil
} | go | func (env *environ) InstanceAvailabilityZoneNames(ctx context.ProviderCallContext, ids []instance.Id) ([]string, error) {
if err := env.checkBroken("InstanceAvailabilityZoneNames"); err != nil {
return nil, errors.NotSupportedf("instance availability zones")
}
availabilityZones, err := env.AvailabilityZones(ctx)
if err != nil {
return nil, err
}
azMaxIndex := len(availabilityZones) - 1
azIndex := 0
returnValue := make([]string, len(ids))
for i := range ids {
if availabilityZones[azIndex].Available() {
returnValue[i] = availabilityZones[azIndex].Name()
} else {
// Based on knowledge of how the AZs are setup above
// in AvailabilityZones()
azIndex += 1
returnValue[i] = availabilityZones[azIndex].Name()
}
azIndex += 1
if azIndex == azMaxIndex {
azIndex = 0
}
}
return returnValue, nil
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"InstanceAvailabilityZoneNames",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"ids",
"[",
"]",
"instance",
".",
"Id",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"err",
":=",
"env",
".",
"checkBroken",
"(",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"availabilityZones",
",",
"err",
":=",
"env",
".",
"AvailabilityZones",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"azMaxIndex",
":=",
"len",
"(",
"availabilityZones",
")",
"-",
"1",
"\n",
"azIndex",
":=",
"0",
"\n",
"returnValue",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"ids",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"ids",
"{",
"if",
"availabilityZones",
"[",
"azIndex",
"]",
".",
"Available",
"(",
")",
"{",
"returnValue",
"[",
"i",
"]",
"=",
"availabilityZones",
"[",
"azIndex",
"]",
".",
"Name",
"(",
")",
"\n",
"}",
"else",
"{",
"// Based on knowledge of how the AZs are setup above",
"// in AvailabilityZones()",
"azIndex",
"+=",
"1",
"\n",
"returnValue",
"[",
"i",
"]",
"=",
"availabilityZones",
"[",
"azIndex",
"]",
".",
"Name",
"(",
")",
"\n",
"}",
"\n",
"azIndex",
"+=",
"1",
"\n",
"if",
"azIndex",
"==",
"azMaxIndex",
"{",
"azIndex",
"=",
"0",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"returnValue",
",",
"nil",
"\n",
"}"
] | // InstanceAvailabilityZoneNames implements environs.ZonedEnviron. | [
"InstanceAvailabilityZoneNames",
"implements",
"environs",
".",
"ZonedEnviron",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L1478-L1504 |
5,074 | juju/juju | provider/dummy/environs.go | Subnets | func (env *environ) Subnets(ctx context.ProviderCallContext, instId instance.Id, subnetIds []network.Id) ([]network.SubnetInfo, error) {
if err := env.checkBroken("Subnets"); err != nil {
return nil, err
}
estate, err := env.state()
if err != nil {
return nil, err
}
estate.mu.Lock()
defer estate.mu.Unlock()
if ok, _ := env.SupportsSpaceDiscovery(ctx); ok {
// Space discovery needs more subnets to work with.
return env.subnetsForSpaceDiscovery(estate)
}
allSubnets := []network.SubnetInfo{{
CIDR: "0.10.0.0/24",
ProviderId: "dummy-private",
AvailabilityZones: []string{"zone1", "zone2"},
}, {
CIDR: "0.20.0.0/24",
ProviderId: "dummy-public",
}}
// Filter result by ids, if given.
var result []network.SubnetInfo
for _, subId := range subnetIds {
switch subId {
case "dummy-private":
result = append(result, allSubnets[0])
case "dummy-public":
result = append(result, allSubnets[1])
}
}
if len(subnetIds) == 0 {
result = append([]network.SubnetInfo{}, allSubnets...)
}
if len(result) == 0 {
// No results, so just return them now.
estate.ops <- OpSubnets{
Env: env.name,
InstanceId: instId,
SubnetIds: subnetIds,
Info: result,
}
return result, nil
}
estate.ops <- OpSubnets{
Env: env.name,
InstanceId: instId,
SubnetIds: subnetIds,
Info: result,
}
return result, nil
} | go | func (env *environ) Subnets(ctx context.ProviderCallContext, instId instance.Id, subnetIds []network.Id) ([]network.SubnetInfo, error) {
if err := env.checkBroken("Subnets"); err != nil {
return nil, err
}
estate, err := env.state()
if err != nil {
return nil, err
}
estate.mu.Lock()
defer estate.mu.Unlock()
if ok, _ := env.SupportsSpaceDiscovery(ctx); ok {
// Space discovery needs more subnets to work with.
return env.subnetsForSpaceDiscovery(estate)
}
allSubnets := []network.SubnetInfo{{
CIDR: "0.10.0.0/24",
ProviderId: "dummy-private",
AvailabilityZones: []string{"zone1", "zone2"},
}, {
CIDR: "0.20.0.0/24",
ProviderId: "dummy-public",
}}
// Filter result by ids, if given.
var result []network.SubnetInfo
for _, subId := range subnetIds {
switch subId {
case "dummy-private":
result = append(result, allSubnets[0])
case "dummy-public":
result = append(result, allSubnets[1])
}
}
if len(subnetIds) == 0 {
result = append([]network.SubnetInfo{}, allSubnets...)
}
if len(result) == 0 {
// No results, so just return them now.
estate.ops <- OpSubnets{
Env: env.name,
InstanceId: instId,
SubnetIds: subnetIds,
Info: result,
}
return result, nil
}
estate.ops <- OpSubnets{
Env: env.name,
InstanceId: instId,
SubnetIds: subnetIds,
Info: result,
}
return result, nil
} | [
"func",
"(",
"env",
"*",
"environ",
")",
"Subnets",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"instId",
"instance",
".",
"Id",
",",
"subnetIds",
"[",
"]",
"network",
".",
"Id",
")",
"(",
"[",
"]",
"network",
".",
"SubnetInfo",
",",
"error",
")",
"{",
"if",
"err",
":=",
"env",
".",
"checkBroken",
"(",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"estate",
",",
"err",
":=",
"env",
".",
"state",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"estate",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"estate",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"ok",
",",
"_",
":=",
"env",
".",
"SupportsSpaceDiscovery",
"(",
"ctx",
")",
";",
"ok",
"{",
"// Space discovery needs more subnets to work with.",
"return",
"env",
".",
"subnetsForSpaceDiscovery",
"(",
"estate",
")",
"\n",
"}",
"\n\n",
"allSubnets",
":=",
"[",
"]",
"network",
".",
"SubnetInfo",
"{",
"{",
"CIDR",
":",
"\"",
"\"",
",",
"ProviderId",
":",
"\"",
"\"",
",",
"AvailabilityZones",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
",",
"}",
",",
"{",
"CIDR",
":",
"\"",
"\"",
",",
"ProviderId",
":",
"\"",
"\"",
",",
"}",
"}",
"\n\n",
"// Filter result by ids, if given.",
"var",
"result",
"[",
"]",
"network",
".",
"SubnetInfo",
"\n",
"for",
"_",
",",
"subId",
":=",
"range",
"subnetIds",
"{",
"switch",
"subId",
"{",
"case",
"\"",
"\"",
":",
"result",
"=",
"append",
"(",
"result",
",",
"allSubnets",
"[",
"0",
"]",
")",
"\n",
"case",
"\"",
"\"",
":",
"result",
"=",
"append",
"(",
"result",
",",
"allSubnets",
"[",
"1",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"subnetIds",
")",
"==",
"0",
"{",
"result",
"=",
"append",
"(",
"[",
"]",
"network",
".",
"SubnetInfo",
"{",
"}",
",",
"allSubnets",
"...",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"result",
")",
"==",
"0",
"{",
"// No results, so just return them now.",
"estate",
".",
"ops",
"<-",
"OpSubnets",
"{",
"Env",
":",
"env",
".",
"name",
",",
"InstanceId",
":",
"instId",
",",
"SubnetIds",
":",
"subnetIds",
",",
"Info",
":",
"result",
",",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}",
"\n\n",
"estate",
".",
"ops",
"<-",
"OpSubnets",
"{",
"Env",
":",
"env",
".",
"name",
",",
"InstanceId",
":",
"instId",
",",
"SubnetIds",
":",
"subnetIds",
",",
"Info",
":",
"result",
",",
"}",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // Subnets implements environs.Environ.Subnets. | [
"Subnets",
"implements",
"environs",
".",
"Environ",
".",
"Subnets",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L1512-L1569 |
5,075 | juju/juju | provider/dummy/environs.go | SetInstanceAddresses | func SetInstanceAddresses(inst instances.Instance, addrs []network.Address) {
inst0 := inst.(*dummyInstance)
inst0.mu.Lock()
inst0.addresses = append(inst0.addresses[:0], addrs...)
logger.Debugf("setting instance %q addresses to %v", inst0.Id(), addrs)
inst0.mu.Unlock()
} | go | func SetInstanceAddresses(inst instances.Instance, addrs []network.Address) {
inst0 := inst.(*dummyInstance)
inst0.mu.Lock()
inst0.addresses = append(inst0.addresses[:0], addrs...)
logger.Debugf("setting instance %q addresses to %v", inst0.Id(), addrs)
inst0.mu.Unlock()
} | [
"func",
"SetInstanceAddresses",
"(",
"inst",
"instances",
".",
"Instance",
",",
"addrs",
"[",
"]",
"network",
".",
"Address",
")",
"{",
"inst0",
":=",
"inst",
".",
"(",
"*",
"dummyInstance",
")",
"\n",
"inst0",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"inst0",
".",
"addresses",
"=",
"append",
"(",
"inst0",
".",
"addresses",
"[",
":",
"0",
"]",
",",
"addrs",
"...",
")",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"inst0",
".",
"Id",
"(",
")",
",",
"addrs",
")",
"\n",
"inst0",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // SetInstanceAddresses sets the addresses associated with the given
// dummy instance. | [
"SetInstanceAddresses",
"sets",
"the",
"addresses",
"associated",
"with",
"the",
"given",
"dummy",
"instance",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L1730-L1736 |
5,076 | juju/juju | provider/dummy/environs.go | SetInstanceStatus | func SetInstanceStatus(inst instances.Instance, status string) {
inst0 := inst.(*dummyInstance)
inst0.mu.Lock()
inst0.status = status
inst0.mu.Unlock()
} | go | func SetInstanceStatus(inst instances.Instance, status string) {
inst0 := inst.(*dummyInstance)
inst0.mu.Lock()
inst0.status = status
inst0.mu.Unlock()
} | [
"func",
"SetInstanceStatus",
"(",
"inst",
"instances",
".",
"Instance",
",",
"status",
"string",
")",
"{",
"inst0",
":=",
"inst",
".",
"(",
"*",
"dummyInstance",
")",
"\n",
"inst0",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"inst0",
".",
"status",
"=",
"status",
"\n",
"inst0",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // SetInstanceStatus sets the status associated with the given
// dummy instance. | [
"SetInstanceStatus",
"sets",
"the",
"status",
"associated",
"with",
"the",
"given",
"dummy",
"instance",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L1740-L1745 |
5,077 | juju/juju | provider/dummy/environs.go | SetInstanceBroken | func SetInstanceBroken(inst instances.Instance, methods ...string) {
inst0 := inst.(*dummyInstance)
inst0.mu.Lock()
inst0.broken = methods
inst0.mu.Unlock()
} | go | func SetInstanceBroken(inst instances.Instance, methods ...string) {
inst0 := inst.(*dummyInstance)
inst0.mu.Lock()
inst0.broken = methods
inst0.mu.Unlock()
} | [
"func",
"SetInstanceBroken",
"(",
"inst",
"instances",
".",
"Instance",
",",
"methods",
"...",
"string",
")",
"{",
"inst0",
":=",
"inst",
".",
"(",
"*",
"dummyInstance",
")",
"\n",
"inst0",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"inst0",
".",
"broken",
"=",
"methods",
"\n",
"inst0",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // SetInstanceBroken marks the named methods of the instance as broken.
// Any previously broken methods not in the set will no longer be broken. | [
"SetInstanceBroken",
"marks",
"the",
"named",
"methods",
"of",
"the",
"instance",
"as",
"broken",
".",
"Any",
"previously",
"broken",
"methods",
"not",
"in",
"the",
"set",
"will",
"no",
"longer",
"be",
"broken",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L1749-L1754 |
5,078 | juju/juju | provider/dummy/environs.go | SSHAddresses | func (*environ) SSHAddresses(ctx context.ProviderCallContext, addresses []network.Address) ([]network.Address, error) {
var rv []network.Address
for _, addr := range addresses {
if addr.Value != "100.100.100.100" {
rv = append(rv, addr)
}
}
return rv, nil
} | go | func (*environ) SSHAddresses(ctx context.ProviderCallContext, addresses []network.Address) ([]network.Address, error) {
var rv []network.Address
for _, addr := range addresses {
if addr.Value != "100.100.100.100" {
rv = append(rv, addr)
}
}
return rv, nil
} | [
"func",
"(",
"*",
"environ",
")",
"SSHAddresses",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"addresses",
"[",
"]",
"network",
".",
"Address",
")",
"(",
"[",
"]",
"network",
".",
"Address",
",",
"error",
")",
"{",
"var",
"rv",
"[",
"]",
"network",
".",
"Address",
"\n",
"for",
"_",
",",
"addr",
":=",
"range",
"addresses",
"{",
"if",
"addr",
".",
"Value",
"!=",
"\"",
"\"",
"{",
"rv",
"=",
"append",
"(",
"rv",
",",
"addr",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"rv",
",",
"nil",
"\n",
"}"
] | // SSHAddresses implements environs.SSHAddresses.
// For testing we cut "100.100.100.100" out of this list. | [
"SSHAddresses",
"implements",
"environs",
".",
"SSHAddresses",
".",
"For",
"testing",
"we",
"cut",
"100",
".",
"100",
".",
"100",
".",
"100",
"out",
"of",
"this",
"list",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L1918-L1926 |
5,079 | juju/juju | provider/dummy/environs.go | SetAgentStatus | func (e *environ) SetAgentStatus(agent string, status presence.Status) {
estate, err := e.state()
if err != nil {
panic(err)
}
estate.presence.agent[agent] = status
} | go | func (e *environ) SetAgentStatus(agent string, status presence.Status) {
estate, err := e.state()
if err != nil {
panic(err)
}
estate.presence.agent[agent] = status
} | [
"func",
"(",
"e",
"*",
"environ",
")",
"SetAgentStatus",
"(",
"agent",
"string",
",",
"status",
"presence",
".",
"Status",
")",
"{",
"estate",
",",
"err",
":=",
"e",
".",
"state",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"estate",
".",
"presence",
".",
"agent",
"[",
"agent",
"]",
"=",
"status",
"\n",
"}"
] | // SetAgentStatus sets the presence for a particular agent in the fake presence implementation. | [
"SetAgentStatus",
"sets",
"the",
"presence",
"for",
"a",
"particular",
"agent",
"in",
"the",
"fake",
"presence",
"implementation",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/dummy/environs.go#L1934-L1940 |
5,080 | juju/juju | provider/azure/internal/imageutils/images.go | SeriesImage | func SeriesImage(
ctx context.ProviderCallContext,
series, stream, location string,
client compute.VirtualMachineImagesClient,
) (*instances.Image, error) {
seriesOS, err := jujuseries.GetOSFromSeries(series)
if err != nil {
return nil, errors.Trace(err)
}
var publisher, offering, sku string
switch seriesOS {
case os.Ubuntu:
publisher = ubuntuPublisher
offering = ubuntuOffering
sku, err = ubuntuSKU(ctx, series, stream, location, client)
if err != nil {
return nil, errors.Annotatef(err, "selecting SKU for %s", series)
}
case os.Windows:
switch series {
case "win81":
publisher = windowsPublisher
offering = windowsOffering
sku = "8.1-Enterprise-N"
case "win10":
publisher = windowsPublisher
offering = windowsOffering
sku = "10-Enterprise"
case "win2012":
publisher = windowsServerPublisher
offering = windowsServerOffering
sku = "2012-Datacenter"
case "win2012r2":
publisher = windowsServerPublisher
offering = windowsServerOffering
sku = "2012-R2-Datacenter"
default:
return nil, errors.NotSupportedf("deploying %s", series)
}
case os.CentOS:
publisher = centOSPublisher
offering = centOSOffering
switch series {
case "centos7":
sku = "7.3"
default:
return nil, errors.NotSupportedf("deploying %s", series)
}
default:
// TODO(axw) CentOS
return nil, errors.NotSupportedf("deploying %s", seriesOS)
}
return &instances.Image{
Id: fmt.Sprintf("%s:%s:%s:latest", publisher, offering, sku),
Arch: arch.AMD64,
VirtType: "Hyper-V",
}, nil
} | go | func SeriesImage(
ctx context.ProviderCallContext,
series, stream, location string,
client compute.VirtualMachineImagesClient,
) (*instances.Image, error) {
seriesOS, err := jujuseries.GetOSFromSeries(series)
if err != nil {
return nil, errors.Trace(err)
}
var publisher, offering, sku string
switch seriesOS {
case os.Ubuntu:
publisher = ubuntuPublisher
offering = ubuntuOffering
sku, err = ubuntuSKU(ctx, series, stream, location, client)
if err != nil {
return nil, errors.Annotatef(err, "selecting SKU for %s", series)
}
case os.Windows:
switch series {
case "win81":
publisher = windowsPublisher
offering = windowsOffering
sku = "8.1-Enterprise-N"
case "win10":
publisher = windowsPublisher
offering = windowsOffering
sku = "10-Enterprise"
case "win2012":
publisher = windowsServerPublisher
offering = windowsServerOffering
sku = "2012-Datacenter"
case "win2012r2":
publisher = windowsServerPublisher
offering = windowsServerOffering
sku = "2012-R2-Datacenter"
default:
return nil, errors.NotSupportedf("deploying %s", series)
}
case os.CentOS:
publisher = centOSPublisher
offering = centOSOffering
switch series {
case "centos7":
sku = "7.3"
default:
return nil, errors.NotSupportedf("deploying %s", series)
}
default:
// TODO(axw) CentOS
return nil, errors.NotSupportedf("deploying %s", seriesOS)
}
return &instances.Image{
Id: fmt.Sprintf("%s:%s:%s:latest", publisher, offering, sku),
Arch: arch.AMD64,
VirtType: "Hyper-V",
}, nil
} | [
"func",
"SeriesImage",
"(",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"series",
",",
"stream",
",",
"location",
"string",
",",
"client",
"compute",
".",
"VirtualMachineImagesClient",
",",
")",
"(",
"*",
"instances",
".",
"Image",
",",
"error",
")",
"{",
"seriesOS",
",",
"err",
":=",
"jujuseries",
".",
"GetOSFromSeries",
"(",
"series",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"publisher",
",",
"offering",
",",
"sku",
"string",
"\n",
"switch",
"seriesOS",
"{",
"case",
"os",
".",
"Ubuntu",
":",
"publisher",
"=",
"ubuntuPublisher",
"\n",
"offering",
"=",
"ubuntuOffering",
"\n",
"sku",
",",
"err",
"=",
"ubuntuSKU",
"(",
"ctx",
",",
"series",
",",
"stream",
",",
"location",
",",
"client",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"series",
")",
"\n",
"}",
"\n\n",
"case",
"os",
".",
"Windows",
":",
"switch",
"series",
"{",
"case",
"\"",
"\"",
":",
"publisher",
"=",
"windowsPublisher",
"\n",
"offering",
"=",
"windowsOffering",
"\n",
"sku",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"publisher",
"=",
"windowsPublisher",
"\n",
"offering",
"=",
"windowsOffering",
"\n",
"sku",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"publisher",
"=",
"windowsServerPublisher",
"\n",
"offering",
"=",
"windowsServerOffering",
"\n",
"sku",
"=",
"\"",
"\"",
"\n",
"case",
"\"",
"\"",
":",
"publisher",
"=",
"windowsServerPublisher",
"\n",
"offering",
"=",
"windowsServerOffering",
"\n",
"sku",
"=",
"\"",
"\"",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
",",
"series",
")",
"\n",
"}",
"\n\n",
"case",
"os",
".",
"CentOS",
":",
"publisher",
"=",
"centOSPublisher",
"\n",
"offering",
"=",
"centOSOffering",
"\n",
"switch",
"series",
"{",
"case",
"\"",
"\"",
":",
"sku",
"=",
"\"",
"\"",
"\n",
"default",
":",
"return",
"nil",
",",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
",",
"series",
")",
"\n",
"}",
"\n\n",
"default",
":",
"// TODO(axw) CentOS",
"return",
"nil",
",",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
",",
"seriesOS",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"instances",
".",
"Image",
"{",
"Id",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"publisher",
",",
"offering",
",",
"sku",
")",
",",
"Arch",
":",
"arch",
".",
"AMD64",
",",
"VirtType",
":",
"\"",
"\"",
",",
"}",
",",
"nil",
"\n",
"}"
] | // SeriesImage gets an instances.Image for the specified series, image stream
// and location. The resulting Image's ID is in the URN format expected by
// Azure Resource Manager.
//
// For Ubuntu, we query the SKUs to determine the most recent point release
// for a series. | [
"SeriesImage",
"gets",
"an",
"instances",
".",
"Image",
"for",
"the",
"specified",
"series",
"image",
"stream",
"and",
"location",
".",
"The",
"resulting",
"Image",
"s",
"ID",
"is",
"in",
"the",
"URN",
"format",
"expected",
"by",
"Azure",
"Resource",
"Manager",
".",
"For",
"Ubuntu",
"we",
"query",
"the",
"SKUs",
"to",
"determine",
"the",
"most",
"recent",
"point",
"release",
"for",
"a",
"series",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/imageutils/images.go#L51-L113 |
5,081 | juju/juju | state/address.go | controllerAddresses | func (st *State) controllerAddresses() ([]string, error) {
cinfo, err := st.ControllerInfo()
if err != nil {
return nil, errors.Trace(err)
}
var machines mongo.Collection
var closer SessionCloser
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
if model.ModelTag() == cinfo.ModelTag {
machines, closer = st.db().GetCollection(machinesC)
} else {
machines, closer = st.db().GetCollectionFor(cinfo.ModelTag.Id(), machinesC)
}
defer closer()
type addressMachine struct {
Addresses []address
}
var allAddresses []addressMachine
// TODO(rog) 2013/10/14 index machines on jobs.
err = machines.Find(bson.D{{"jobs", JobManageModel}}).All(&allAddresses)
if err != nil {
return nil, err
}
if len(allAddresses) == 0 {
return nil, errors.New("no controller machines found")
}
apiAddrs := make([]string, 0, len(allAddresses))
for _, addrs := range allAddresses {
naddrs := networkAddresses(addrs.Addresses)
addr, ok := network.SelectControllerAddress(naddrs, false)
if ok {
apiAddrs = append(apiAddrs, addr.Value)
}
}
if len(apiAddrs) == 0 {
return nil, errors.New("no controller machines with addresses found")
}
return apiAddrs, nil
} | go | func (st *State) controllerAddresses() ([]string, error) {
cinfo, err := st.ControllerInfo()
if err != nil {
return nil, errors.Trace(err)
}
var machines mongo.Collection
var closer SessionCloser
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
if model.ModelTag() == cinfo.ModelTag {
machines, closer = st.db().GetCollection(machinesC)
} else {
machines, closer = st.db().GetCollectionFor(cinfo.ModelTag.Id(), machinesC)
}
defer closer()
type addressMachine struct {
Addresses []address
}
var allAddresses []addressMachine
// TODO(rog) 2013/10/14 index machines on jobs.
err = machines.Find(bson.D{{"jobs", JobManageModel}}).All(&allAddresses)
if err != nil {
return nil, err
}
if len(allAddresses) == 0 {
return nil, errors.New("no controller machines found")
}
apiAddrs := make([]string, 0, len(allAddresses))
for _, addrs := range allAddresses {
naddrs := networkAddresses(addrs.Addresses)
addr, ok := network.SelectControllerAddress(naddrs, false)
if ok {
apiAddrs = append(apiAddrs, addr.Value)
}
}
if len(apiAddrs) == 0 {
return nil, errors.New("no controller machines with addresses found")
}
return apiAddrs, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"controllerAddresses",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"cinfo",
",",
"err",
":=",
"st",
".",
"ControllerInfo",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"machines",
"mongo",
".",
"Collection",
"\n",
"var",
"closer",
"SessionCloser",
"\n",
"model",
",",
"err",
":=",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"model",
".",
"ModelTag",
"(",
")",
"==",
"cinfo",
".",
"ModelTag",
"{",
"machines",
",",
"closer",
"=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"machinesC",
")",
"\n",
"}",
"else",
"{",
"machines",
",",
"closer",
"=",
"st",
".",
"db",
"(",
")",
".",
"GetCollectionFor",
"(",
"cinfo",
".",
"ModelTag",
".",
"Id",
"(",
")",
",",
"machinesC",
")",
"\n",
"}",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"type",
"addressMachine",
"struct",
"{",
"Addresses",
"[",
"]",
"address",
"\n",
"}",
"\n",
"var",
"allAddresses",
"[",
"]",
"addressMachine",
"\n",
"// TODO(rog) 2013/10/14 index machines on jobs.",
"err",
"=",
"machines",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"JobManageModel",
"}",
"}",
")",
".",
"All",
"(",
"&",
"allAddresses",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"allAddresses",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"apiAddrs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"allAddresses",
")",
")",
"\n",
"for",
"_",
",",
"addrs",
":=",
"range",
"allAddresses",
"{",
"naddrs",
":=",
"networkAddresses",
"(",
"addrs",
".",
"Addresses",
")",
"\n",
"addr",
",",
"ok",
":=",
"network",
".",
"SelectControllerAddress",
"(",
"naddrs",
",",
"false",
")",
"\n",
"if",
"ok",
"{",
"apiAddrs",
"=",
"append",
"(",
"apiAddrs",
",",
"addr",
".",
"Value",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"apiAddrs",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"apiAddrs",
",",
"nil",
"\n",
"}"
] | // controllerAddresses returns the list of internal addresses of the state
// server machines. | [
"controllerAddresses",
"returns",
"the",
"list",
"of",
"internal",
"addresses",
"of",
"the",
"state",
"server",
"machines",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L25-L68 |
5,082 | juju/juju | state/address.go | Addresses | func (st *State) Addresses() ([]string, error) {
addrs, err := st.controllerAddresses()
if err != nil {
return nil, errors.Trace(err)
}
config, err := st.ControllerConfig()
if err != nil {
return nil, errors.Trace(err)
}
return appendPort(addrs, config.StatePort()), nil
} | go | func (st *State) Addresses() ([]string, error) {
addrs, err := st.controllerAddresses()
if err != nil {
return nil, errors.Trace(err)
}
config, err := st.ControllerConfig()
if err != nil {
return nil, errors.Trace(err)
}
return appendPort(addrs, config.StatePort()), nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"Addresses",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"addrs",
",",
"err",
":=",
"st",
".",
"controllerAddresses",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"config",
",",
"err",
":=",
"st",
".",
"ControllerConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"appendPort",
"(",
"addrs",
",",
"config",
".",
"StatePort",
"(",
")",
")",
",",
"nil",
"\n",
"}"
] | // Addresses returns the list of cloud-internal addresses that
// can be used to connect to the state. | [
"Addresses",
"returns",
"the",
"list",
"of",
"cloud",
"-",
"internal",
"addresses",
"that",
"can",
"be",
"used",
"to",
"connect",
"to",
"the",
"state",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L80-L90 |
5,083 | juju/juju | state/address.go | filterHostPortsForManagementSpace | func (st *State) filterHostPortsForManagementSpace(apiHostPorts [][]network.HostPort) ([][]network.HostPort, error) {
config, err := st.ControllerConfig()
if err != nil {
return nil, err
}
var hostPortsForAgents [][]network.HostPort
if mgmtSpace := config.JujuManagementSpace(); mgmtSpace != "" {
hostPortsForAgents = make([][]network.HostPort, len(apiHostPorts))
sp := network.SpaceName(mgmtSpace)
for i := range apiHostPorts {
if filtered, ok := network.SelectHostPortsBySpaceNames(apiHostPorts[i], sp); ok {
hostPortsForAgents[i] = filtered
} else {
hostPortsForAgents[i] = apiHostPorts[i]
}
}
} else {
hostPortsForAgents = apiHostPorts
}
return hostPortsForAgents, nil
} | go | func (st *State) filterHostPortsForManagementSpace(apiHostPorts [][]network.HostPort) ([][]network.HostPort, error) {
config, err := st.ControllerConfig()
if err != nil {
return nil, err
}
var hostPortsForAgents [][]network.HostPort
if mgmtSpace := config.JujuManagementSpace(); mgmtSpace != "" {
hostPortsForAgents = make([][]network.HostPort, len(apiHostPorts))
sp := network.SpaceName(mgmtSpace)
for i := range apiHostPorts {
if filtered, ok := network.SelectHostPortsBySpaceNames(apiHostPorts[i], sp); ok {
hostPortsForAgents[i] = filtered
} else {
hostPortsForAgents[i] = apiHostPorts[i]
}
}
} else {
hostPortsForAgents = apiHostPorts
}
return hostPortsForAgents, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"filterHostPortsForManagementSpace",
"(",
"apiHostPorts",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
")",
"(",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
",",
"error",
")",
"{",
"config",
",",
"err",
":=",
"st",
".",
"ControllerConfig",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"hostPortsForAgents",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
"\n",
"if",
"mgmtSpace",
":=",
"config",
".",
"JujuManagementSpace",
"(",
")",
";",
"mgmtSpace",
"!=",
"\"",
"\"",
"{",
"hostPortsForAgents",
"=",
"make",
"(",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
",",
"len",
"(",
"apiHostPorts",
")",
")",
"\n",
"sp",
":=",
"network",
".",
"SpaceName",
"(",
"mgmtSpace",
")",
"\n",
"for",
"i",
":=",
"range",
"apiHostPorts",
"{",
"if",
"filtered",
",",
"ok",
":=",
"network",
".",
"SelectHostPortsBySpaceNames",
"(",
"apiHostPorts",
"[",
"i",
"]",
",",
"sp",
")",
";",
"ok",
"{",
"hostPortsForAgents",
"[",
"i",
"]",
"=",
"filtered",
"\n",
"}",
"else",
"{",
"hostPortsForAgents",
"[",
"i",
"]",
"=",
"apiHostPorts",
"[",
"i",
"]",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"{",
"hostPortsForAgents",
"=",
"apiHostPorts",
"\n",
"}",
"\n",
"return",
"hostPortsForAgents",
",",
"nil",
"\n",
"}"
] | // filterHostPortsForManagementSpace filters the collection of API addresses
// based on the configured management space for the controller.
// If there is no space configured, or if the one of the slices is filtered down
// to zero elements, just use the unfiltered slice for safety - we do not
// want to cut off communication to the controller based on erroneous config. | [
"filterHostPortsForManagementSpace",
"filters",
"the",
"collection",
"of",
"API",
"addresses",
"based",
"on",
"the",
"configured",
"management",
"space",
"for",
"the",
"controller",
".",
"If",
"there",
"is",
"no",
"space",
"configured",
"or",
"if",
"the",
"one",
"of",
"the",
"slices",
"is",
"filtered",
"down",
"to",
"zero",
"elements",
"just",
"use",
"the",
"unfiltered",
"slice",
"for",
"safety",
"-",
"we",
"do",
"not",
"want",
"to",
"cut",
"off",
"communication",
"to",
"the",
"controller",
"based",
"on",
"erroneous",
"config",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L190-L211 |
5,084 | juju/juju | state/address.go | APIHostPortsForAgents | func (st *State) APIHostPortsForAgents() ([][]network.HostPort, error) {
isCAASCtrl, err := st.isCAASController()
if err != nil {
return nil, errors.Trace(err)
}
if isCAASCtrl {
// TODO(caas): add test for this once we have the replacement for Jujuconnsuite.
return st.apiHostPortsForCAAS(false)
}
hps, err := st.apiHostPortsForKey(apiHostPortsForAgentsKey)
if err != nil {
if err == mgo.ErrNotFound {
logger.Debugf("No document for %s; using %s", apiHostPortsForAgentsKey, apiHostPortsKey)
return st.APIHostPortsForClients()
}
return nil, errors.Trace(err)
}
return hps, nil
} | go | func (st *State) APIHostPortsForAgents() ([][]network.HostPort, error) {
isCAASCtrl, err := st.isCAASController()
if err != nil {
return nil, errors.Trace(err)
}
if isCAASCtrl {
// TODO(caas): add test for this once we have the replacement for Jujuconnsuite.
return st.apiHostPortsForCAAS(false)
}
hps, err := st.apiHostPortsForKey(apiHostPortsForAgentsKey)
if err != nil {
if err == mgo.ErrNotFound {
logger.Debugf("No document for %s; using %s", apiHostPortsForAgentsKey, apiHostPortsKey)
return st.APIHostPortsForClients()
}
return nil, errors.Trace(err)
}
return hps, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"APIHostPortsForAgents",
"(",
")",
"(",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
",",
"error",
")",
"{",
"isCAASCtrl",
",",
"err",
":=",
"st",
".",
"isCAASController",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"isCAASCtrl",
"{",
"// TODO(caas): add test for this once we have the replacement for Jujuconnsuite.",
"return",
"st",
".",
"apiHostPortsForCAAS",
"(",
"false",
")",
"\n",
"}",
"\n\n",
"hps",
",",
"err",
":=",
"st",
".",
"apiHostPortsForKey",
"(",
"apiHostPortsForAgentsKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"err",
"==",
"mgo",
".",
"ErrNotFound",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"apiHostPortsForAgentsKey",
",",
"apiHostPortsKey",
")",
"\n",
"return",
"st",
".",
"APIHostPortsForClients",
"(",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"hps",
",",
"nil",
"\n",
"}"
] | // APIHostPortsForAgents returns the collection of API addresses that should
// be used by agents.
// If the controller model is CAAS type, the return will be the controller
// k8s service addresses in cloud service.
// If there is no management network space configured for the controller,
// or if the space is misconfigured, the return will be the same as
// APIHostPortsForClients.
// Otherwise the returned addresses will correspond with the management net space.
// If there is no document at all, we simply fall back to APIHostPortsForClients. | [
"APIHostPortsForAgents",
"returns",
"the",
"collection",
"of",
"API",
"addresses",
"that",
"should",
"be",
"used",
"by",
"agents",
".",
"If",
"the",
"controller",
"model",
"is",
"CAAS",
"type",
"the",
"return",
"will",
"be",
"the",
"controller",
"k8s",
"service",
"addresses",
"in",
"cloud",
"service",
".",
"If",
"there",
"is",
"no",
"management",
"network",
"space",
"configured",
"for",
"the",
"controller",
"or",
"if",
"the",
"space",
"is",
"misconfigured",
"the",
"return",
"will",
"be",
"the",
"same",
"as",
"APIHostPortsForClients",
".",
"Otherwise",
"the",
"returned",
"addresses",
"will",
"correspond",
"with",
"the",
"management",
"net",
"space",
".",
"If",
"there",
"is",
"no",
"document",
"at",
"all",
"we",
"simply",
"fall",
"back",
"to",
"APIHostPortsForClients",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L240-L259 |
5,085 | juju/juju | state/address.go | apiHostPortsForKey | func (st *State) apiHostPortsForKey(key string) ([][]network.HostPort, error) {
var doc apiHostPortsDoc
controllers, closer := st.db().GetCollection(controllersC)
defer closer()
err := controllers.Find(bson.D{{"_id", key}}).One(&doc)
if err != nil {
return nil, err
}
return networkHostsPorts(doc.APIHostPorts), nil
} | go | func (st *State) apiHostPortsForKey(key string) ([][]network.HostPort, error) {
var doc apiHostPortsDoc
controllers, closer := st.db().GetCollection(controllersC)
defer closer()
err := controllers.Find(bson.D{{"_id", key}}).One(&doc)
if err != nil {
return nil, err
}
return networkHostsPorts(doc.APIHostPorts), nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"apiHostPortsForKey",
"(",
"key",
"string",
")",
"(",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
",",
"error",
")",
"{",
"var",
"doc",
"apiHostPortsDoc",
"\n",
"controllers",
",",
"closer",
":=",
"st",
".",
"db",
"(",
")",
".",
"GetCollection",
"(",
"controllersC",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n",
"err",
":=",
"controllers",
".",
"Find",
"(",
"bson",
".",
"D",
"{",
"{",
"\"",
"\"",
",",
"key",
"}",
"}",
")",
".",
"One",
"(",
"&",
"doc",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"networkHostsPorts",
"(",
"doc",
".",
"APIHostPorts",
")",
",",
"nil",
"\n",
"}"
] | // apiHostPortsForKey returns API addresses extracted from the document
// identified by the input key. | [
"apiHostPortsForKey",
"returns",
"API",
"addresses",
"extracted",
"from",
"the",
"document",
"identified",
"by",
"the",
"input",
"key",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L307-L316 |
5,086 | juju/juju | state/address.go | fromNetworkAddress | func fromNetworkAddress(netAddr network.Address, origin Origin) address {
return address{
Value: netAddr.Value,
AddressType: string(netAddr.Type),
Scope: string(netAddr.Scope),
Origin: string(origin),
SpaceName: string(netAddr.SpaceName),
}
} | go | func fromNetworkAddress(netAddr network.Address, origin Origin) address {
return address{
Value: netAddr.Value,
AddressType: string(netAddr.Type),
Scope: string(netAddr.Scope),
Origin: string(origin),
SpaceName: string(netAddr.SpaceName),
}
} | [
"func",
"fromNetworkAddress",
"(",
"netAddr",
"network",
".",
"Address",
",",
"origin",
"Origin",
")",
"address",
"{",
"return",
"address",
"{",
"Value",
":",
"netAddr",
".",
"Value",
",",
"AddressType",
":",
"string",
"(",
"netAddr",
".",
"Type",
")",
",",
"Scope",
":",
"string",
"(",
"netAddr",
".",
"Scope",
")",
",",
"Origin",
":",
"string",
"(",
"origin",
")",
",",
"SpaceName",
":",
"string",
"(",
"netAddr",
".",
"SpaceName",
")",
",",
"}",
"\n",
"}"
] | // fromNetworkAddress is a convenience helper to create a state type
// out of the network type, here for Address with a given Origin. | [
"fromNetworkAddress",
"is",
"a",
"convenience",
"helper",
"to",
"create",
"a",
"state",
"type",
"out",
"of",
"the",
"network",
"type",
"here",
"for",
"Address",
"with",
"a",
"given",
"Origin",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L347-L355 |
5,087 | juju/juju | state/address.go | networkAddress | func (addr *address) networkAddress() network.Address {
return network.Address{
Value: addr.Value,
Type: network.AddressType(addr.AddressType),
Scope: network.Scope(addr.Scope),
SpaceName: network.SpaceName(addr.SpaceName),
}
} | go | func (addr *address) networkAddress() network.Address {
return network.Address{
Value: addr.Value,
Type: network.AddressType(addr.AddressType),
Scope: network.Scope(addr.Scope),
SpaceName: network.SpaceName(addr.SpaceName),
}
} | [
"func",
"(",
"addr",
"*",
"address",
")",
"networkAddress",
"(",
")",
"network",
".",
"Address",
"{",
"return",
"network",
".",
"Address",
"{",
"Value",
":",
"addr",
".",
"Value",
",",
"Type",
":",
"network",
".",
"AddressType",
"(",
"addr",
".",
"AddressType",
")",
",",
"Scope",
":",
"network",
".",
"Scope",
"(",
"addr",
".",
"Scope",
")",
",",
"SpaceName",
":",
"network",
".",
"SpaceName",
"(",
"addr",
".",
"SpaceName",
")",
",",
"}",
"\n",
"}"
] | // networkAddress is a convenience helper to return the state type
// as network type, here for Address. | [
"networkAddress",
"is",
"a",
"convenience",
"helper",
"to",
"return",
"the",
"state",
"type",
"as",
"network",
"type",
"here",
"for",
"Address",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L359-L366 |
5,088 | juju/juju | state/address.go | fromNetworkAddresses | func fromNetworkAddresses(netAddrs []network.Address, origin Origin) []address {
addrs := make([]address, len(netAddrs))
for i, netAddr := range netAddrs {
addrs[i] = fromNetworkAddress(netAddr, origin)
}
return addrs
} | go | func fromNetworkAddresses(netAddrs []network.Address, origin Origin) []address {
addrs := make([]address, len(netAddrs))
for i, netAddr := range netAddrs {
addrs[i] = fromNetworkAddress(netAddr, origin)
}
return addrs
} | [
"func",
"fromNetworkAddresses",
"(",
"netAddrs",
"[",
"]",
"network",
".",
"Address",
",",
"origin",
"Origin",
")",
"[",
"]",
"address",
"{",
"addrs",
":=",
"make",
"(",
"[",
"]",
"address",
",",
"len",
"(",
"netAddrs",
")",
")",
"\n",
"for",
"i",
",",
"netAddr",
":=",
"range",
"netAddrs",
"{",
"addrs",
"[",
"i",
"]",
"=",
"fromNetworkAddress",
"(",
"netAddr",
",",
"origin",
")",
"\n",
"}",
"\n",
"return",
"addrs",
"\n",
"}"
] | // fromNetworkAddresses is a convenience helper to create a state type
// out of the network type, here for a slice of Address with a given origin. | [
"fromNetworkAddresses",
"is",
"a",
"convenience",
"helper",
"to",
"create",
"a",
"state",
"type",
"out",
"of",
"the",
"network",
"type",
"here",
"for",
"a",
"slice",
"of",
"Address",
"with",
"a",
"given",
"origin",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L370-L376 |
5,089 | juju/juju | state/address.go | networkAddresses | func networkAddresses(addrs []address) []network.Address {
netAddrs := make([]network.Address, len(addrs))
for i, addr := range addrs {
netAddrs[i] = addr.networkAddress()
}
return netAddrs
} | go | func networkAddresses(addrs []address) []network.Address {
netAddrs := make([]network.Address, len(addrs))
for i, addr := range addrs {
netAddrs[i] = addr.networkAddress()
}
return netAddrs
} | [
"func",
"networkAddresses",
"(",
"addrs",
"[",
"]",
"address",
")",
"[",
"]",
"network",
".",
"Address",
"{",
"netAddrs",
":=",
"make",
"(",
"[",
"]",
"network",
".",
"Address",
",",
"len",
"(",
"addrs",
")",
")",
"\n",
"for",
"i",
",",
"addr",
":=",
"range",
"addrs",
"{",
"netAddrs",
"[",
"i",
"]",
"=",
"addr",
".",
"networkAddress",
"(",
")",
"\n",
"}",
"\n",
"return",
"netAddrs",
"\n",
"}"
] | // networkAddresses is a convenience helper to return the state type
// as network type, here for a slice of Address. | [
"networkAddresses",
"is",
"a",
"convenience",
"helper",
"to",
"return",
"the",
"state",
"type",
"as",
"network",
"type",
"here",
"for",
"a",
"slice",
"of",
"Address",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L380-L386 |
5,090 | juju/juju | state/address.go | fromNetworkHostPort | func fromNetworkHostPort(netHostPort network.HostPort) hostPort {
return hostPort{
Value: netHostPort.Value,
AddressType: string(netHostPort.Type),
Scope: string(netHostPort.Scope),
Port: netHostPort.Port,
SpaceName: string(netHostPort.SpaceName),
}
} | go | func fromNetworkHostPort(netHostPort network.HostPort) hostPort {
return hostPort{
Value: netHostPort.Value,
AddressType: string(netHostPort.Type),
Scope: string(netHostPort.Scope),
Port: netHostPort.Port,
SpaceName: string(netHostPort.SpaceName),
}
} | [
"func",
"fromNetworkHostPort",
"(",
"netHostPort",
"network",
".",
"HostPort",
")",
"hostPort",
"{",
"return",
"hostPort",
"{",
"Value",
":",
"netHostPort",
".",
"Value",
",",
"AddressType",
":",
"string",
"(",
"netHostPort",
".",
"Type",
")",
",",
"Scope",
":",
"string",
"(",
"netHostPort",
".",
"Scope",
")",
",",
"Port",
":",
"netHostPort",
".",
"Port",
",",
"SpaceName",
":",
"string",
"(",
"netHostPort",
".",
"SpaceName",
")",
",",
"}",
"\n",
"}"
] | // fromNetworkHostPort is a convenience helper to create a state type
// out of the network type, here for HostPort. | [
"fromNetworkHostPort",
"is",
"a",
"convenience",
"helper",
"to",
"create",
"a",
"state",
"type",
"out",
"of",
"the",
"network",
"type",
"here",
"for",
"HostPort",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L404-L412 |
5,091 | juju/juju | state/address.go | networkHostPort | func (hp *hostPort) networkHostPort() network.HostPort {
return network.HostPort{
Address: network.Address{
Value: hp.Value,
Type: network.AddressType(hp.AddressType),
Scope: network.Scope(hp.Scope),
SpaceName: network.SpaceName(hp.SpaceName),
},
Port: hp.Port,
}
} | go | func (hp *hostPort) networkHostPort() network.HostPort {
return network.HostPort{
Address: network.Address{
Value: hp.Value,
Type: network.AddressType(hp.AddressType),
Scope: network.Scope(hp.Scope),
SpaceName: network.SpaceName(hp.SpaceName),
},
Port: hp.Port,
}
} | [
"func",
"(",
"hp",
"*",
"hostPort",
")",
"networkHostPort",
"(",
")",
"network",
".",
"HostPort",
"{",
"return",
"network",
".",
"HostPort",
"{",
"Address",
":",
"network",
".",
"Address",
"{",
"Value",
":",
"hp",
".",
"Value",
",",
"Type",
":",
"network",
".",
"AddressType",
"(",
"hp",
".",
"AddressType",
")",
",",
"Scope",
":",
"network",
".",
"Scope",
"(",
"hp",
".",
"Scope",
")",
",",
"SpaceName",
":",
"network",
".",
"SpaceName",
"(",
"hp",
".",
"SpaceName",
")",
",",
"}",
",",
"Port",
":",
"hp",
".",
"Port",
",",
"}",
"\n",
"}"
] | // networkHostPort is a convenience helper to return the state type
// as network type, here for HostPort. | [
"networkHostPort",
"is",
"a",
"convenience",
"helper",
"to",
"return",
"the",
"state",
"type",
"as",
"network",
"type",
"here",
"for",
"HostPort",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L416-L426 |
5,092 | juju/juju | state/address.go | fromNetworkHostsPorts | func fromNetworkHostsPorts(netHostsPorts [][]network.HostPort) [][]hostPort {
hsps := make([][]hostPort, len(netHostsPorts))
for i, netHostPorts := range netHostsPorts {
hsps[i] = make([]hostPort, len(netHostPorts))
for j, netHostPort := range netHostPorts {
hsps[i][j] = fromNetworkHostPort(netHostPort)
}
}
return hsps
} | go | func fromNetworkHostsPorts(netHostsPorts [][]network.HostPort) [][]hostPort {
hsps := make([][]hostPort, len(netHostsPorts))
for i, netHostPorts := range netHostsPorts {
hsps[i] = make([]hostPort, len(netHostPorts))
for j, netHostPort := range netHostPorts {
hsps[i][j] = fromNetworkHostPort(netHostPort)
}
}
return hsps
} | [
"func",
"fromNetworkHostsPorts",
"(",
"netHostsPorts",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
")",
"[",
"]",
"[",
"]",
"hostPort",
"{",
"hsps",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"hostPort",
",",
"len",
"(",
"netHostsPorts",
")",
")",
"\n",
"for",
"i",
",",
"netHostPorts",
":=",
"range",
"netHostsPorts",
"{",
"hsps",
"[",
"i",
"]",
"=",
"make",
"(",
"[",
"]",
"hostPort",
",",
"len",
"(",
"netHostPorts",
")",
")",
"\n",
"for",
"j",
",",
"netHostPort",
":=",
"range",
"netHostPorts",
"{",
"hsps",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"fromNetworkHostPort",
"(",
"netHostPort",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"hsps",
"\n",
"}"
] | // fromNetworkHostsPorts is a helper to create a state type
// out of the network type, here for a nested slice of HostPort. | [
"fromNetworkHostsPorts",
"is",
"a",
"helper",
"to",
"create",
"a",
"state",
"type",
"out",
"of",
"the",
"network",
"type",
"here",
"for",
"a",
"nested",
"slice",
"of",
"HostPort",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L430-L439 |
5,093 | juju/juju | state/address.go | networkHostsPorts | func networkHostsPorts(hsps [][]hostPort) [][]network.HostPort {
netHostsPorts := make([][]network.HostPort, len(hsps))
for i, hps := range hsps {
netHostsPorts[i] = make([]network.HostPort, len(hps))
for j, hp := range hps {
netHostsPorts[i][j] = hp.networkHostPort()
}
}
return netHostsPorts
} | go | func networkHostsPorts(hsps [][]hostPort) [][]network.HostPort {
netHostsPorts := make([][]network.HostPort, len(hsps))
for i, hps := range hsps {
netHostsPorts[i] = make([]network.HostPort, len(hps))
for j, hp := range hps {
netHostsPorts[i][j] = hp.networkHostPort()
}
}
return netHostsPorts
} | [
"func",
"networkHostsPorts",
"(",
"hsps",
"[",
"]",
"[",
"]",
"hostPort",
")",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
"{",
"netHostsPorts",
":=",
"make",
"(",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
",",
"len",
"(",
"hsps",
")",
")",
"\n",
"for",
"i",
",",
"hps",
":=",
"range",
"hsps",
"{",
"netHostsPorts",
"[",
"i",
"]",
"=",
"make",
"(",
"[",
"]",
"network",
".",
"HostPort",
",",
"len",
"(",
"hps",
")",
")",
"\n",
"for",
"j",
",",
"hp",
":=",
"range",
"hps",
"{",
"netHostsPorts",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"hp",
".",
"networkHostPort",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"netHostsPorts",
"\n",
"}"
] | // networkHostsPorts is a convenience helper to return the state type
// as network type, here for a nested slice of HostPort. | [
"networkHostsPorts",
"is",
"a",
"convenience",
"helper",
"to",
"return",
"the",
"state",
"type",
"as",
"network",
"type",
"here",
"for",
"a",
"nested",
"slice",
"of",
"HostPort",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L443-L452 |
5,094 | juju/juju | state/address.go | addressesEqual | func addressesEqual(a, b []network.Address) bool {
return reflect.DeepEqual(a, b)
} | go | func addressesEqual(a, b []network.Address) bool {
return reflect.DeepEqual(a, b)
} | [
"func",
"addressesEqual",
"(",
"a",
",",
"b",
"[",
"]",
"network",
".",
"Address",
")",
"bool",
"{",
"return",
"reflect",
".",
"DeepEqual",
"(",
"a",
",",
"b",
")",
"\n",
"}"
] | // addressEqual checks that two slices of network addresses are equal. | [
"addressEqual",
"checks",
"that",
"two",
"slices",
"of",
"network",
"addresses",
"are",
"equal",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L455-L457 |
5,095 | juju/juju | state/address.go | hostsPortsEqual | func hostsPortsEqual(a, b [][]network.HostPort) bool {
// Make a copy of all the values so we don't mutate the args in order
// to determine if they are the same while we mutate the slice to order them.
aPrime := dupeAndSort(a)
bPrime := dupeAndSort(b)
return reflect.DeepEqual(aPrime, bPrime)
} | go | func hostsPortsEqual(a, b [][]network.HostPort) bool {
// Make a copy of all the values so we don't mutate the args in order
// to determine if they are the same while we mutate the slice to order them.
aPrime := dupeAndSort(a)
bPrime := dupeAndSort(b)
return reflect.DeepEqual(aPrime, bPrime)
} | [
"func",
"hostsPortsEqual",
"(",
"a",
",",
"b",
"[",
"]",
"[",
"]",
"network",
".",
"HostPort",
")",
"bool",
"{",
"// Make a copy of all the values so we don't mutate the args in order",
"// to determine if they are the same while we mutate the slice to order them.",
"aPrime",
":=",
"dupeAndSort",
"(",
"a",
")",
"\n",
"bPrime",
":=",
"dupeAndSort",
"(",
"b",
")",
"\n",
"return",
"reflect",
".",
"DeepEqual",
"(",
"aPrime",
",",
"bPrime",
")",
"\n",
"}"
] | // hostsPortsEqual checks that two arrays of network hostports are equal. | [
"hostsPortsEqual",
"checks",
"that",
"two",
"arrays",
"of",
"network",
"hostports",
"are",
"equal",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/address.go#L495-L501 |
5,096 | juju/juju | apiserver/listener.go | connRateMetric | func (l *throttlingListener) connRateMetric() int {
l.Lock()
defer l.Unlock()
var (
earliestConnTime *time.Time
connCount float64
)
// Figure out the most recent connection timestamp.
startIndex := l.nextSlot - 1
if startIndex < 0 {
startIndex = len(l.connAcceptTimes) - 1
}
latestConnTime := l.connAcceptTimes[startIndex]
if latestConnTime == nil {
return 0
}
// Loop backwards to get the earlier known connection timestamp.
for index := startIndex; index != l.nextSlot; {
if connTime := l.connAcceptTimes[index]; connTime == nil {
break
} else {
earliestConnTime = connTime
}
connCount++
// Stop if we have reached the maximum window in terms how long
// ago the earliest connection was, to avoid stale data skewing results.
if latestConnTime.Sub(*earliestConnTime) > l.lookbackWindow {
break
}
index--
if index < 0 {
index = len(l.connAcceptTimes) - 1
}
}
if connCount < 2 {
return 0
}
// We use as a metric how many connections per 10ms
connRate := connCount * float64(time.Second) / (1.0 + float64(latestConnTime.Sub(*earliestConnTime)))
logger.Tracef("server listener has received %d connections per second", int(connRate))
return int(connRate)
} | go | func (l *throttlingListener) connRateMetric() int {
l.Lock()
defer l.Unlock()
var (
earliestConnTime *time.Time
connCount float64
)
// Figure out the most recent connection timestamp.
startIndex := l.nextSlot - 1
if startIndex < 0 {
startIndex = len(l.connAcceptTimes) - 1
}
latestConnTime := l.connAcceptTimes[startIndex]
if latestConnTime == nil {
return 0
}
// Loop backwards to get the earlier known connection timestamp.
for index := startIndex; index != l.nextSlot; {
if connTime := l.connAcceptTimes[index]; connTime == nil {
break
} else {
earliestConnTime = connTime
}
connCount++
// Stop if we have reached the maximum window in terms how long
// ago the earliest connection was, to avoid stale data skewing results.
if latestConnTime.Sub(*earliestConnTime) > l.lookbackWindow {
break
}
index--
if index < 0 {
index = len(l.connAcceptTimes) - 1
}
}
if connCount < 2 {
return 0
}
// We use as a metric how many connections per 10ms
connRate := connCount * float64(time.Second) / (1.0 + float64(latestConnTime.Sub(*earliestConnTime)))
logger.Tracef("server listener has received %d connections per second", int(connRate))
return int(connRate)
} | [
"func",
"(",
"l",
"*",
"throttlingListener",
")",
"connRateMetric",
"(",
")",
"int",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"(",
"earliestConnTime",
"*",
"time",
".",
"Time",
"\n",
"connCount",
"float64",
"\n",
")",
"\n",
"// Figure out the most recent connection timestamp.",
"startIndex",
":=",
"l",
".",
"nextSlot",
"-",
"1",
"\n",
"if",
"startIndex",
"<",
"0",
"{",
"startIndex",
"=",
"len",
"(",
"l",
".",
"connAcceptTimes",
")",
"-",
"1",
"\n",
"}",
"\n",
"latestConnTime",
":=",
"l",
".",
"connAcceptTimes",
"[",
"startIndex",
"]",
"\n",
"if",
"latestConnTime",
"==",
"nil",
"{",
"return",
"0",
"\n",
"}",
"\n",
"// Loop backwards to get the earlier known connection timestamp.",
"for",
"index",
":=",
"startIndex",
";",
"index",
"!=",
"l",
".",
"nextSlot",
";",
"{",
"if",
"connTime",
":=",
"l",
".",
"connAcceptTimes",
"[",
"index",
"]",
";",
"connTime",
"==",
"nil",
"{",
"break",
"\n",
"}",
"else",
"{",
"earliestConnTime",
"=",
"connTime",
"\n",
"}",
"\n",
"connCount",
"++",
"\n",
"// Stop if we have reached the maximum window in terms how long",
"// ago the earliest connection was, to avoid stale data skewing results.",
"if",
"latestConnTime",
".",
"Sub",
"(",
"*",
"earliestConnTime",
")",
">",
"l",
".",
"lookbackWindow",
"{",
"break",
"\n",
"}",
"\n",
"index",
"--",
"\n",
"if",
"index",
"<",
"0",
"{",
"index",
"=",
"len",
"(",
"l",
".",
"connAcceptTimes",
")",
"-",
"1",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"connCount",
"<",
"2",
"{",
"return",
"0",
"\n",
"}",
"\n",
"// We use as a metric how many connections per 10ms",
"connRate",
":=",
"connCount",
"*",
"float64",
"(",
"time",
".",
"Second",
")",
"/",
"(",
"1.0",
"+",
"float64",
"(",
"latestConnTime",
".",
"Sub",
"(",
"*",
"earliestConnTime",
")",
")",
")",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"int",
"(",
"connRate",
")",
")",
"\n",
"return",
"int",
"(",
"connRate",
")",
"\n",
"}"
] | // connRateMetric returns an int value based on the rate of new connections. | [
"connRateMetric",
"returns",
"an",
"int",
"value",
"based",
"on",
"the",
"rate",
"of",
"new",
"connections",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/listener.go#L48-L90 |
5,097 | juju/juju | apiserver/listener.go | pauseTime | func (l *throttlingListener) pauseTime() time.Duration {
rate := l.connRateMetric()
if rate <= l.lowerThreshold {
return l.minPause
}
if rate >= l.upperThreshold {
return l.maxPause
}
// rate is between min and max so interpolate.
pauseFactor := float64(rate-l.lowerThreshold) / float64(l.upperThreshold-l.lowerThreshold)
return l.minPause + time.Duration(float64(l.maxPause-l.minPause)*pauseFactor)
} | go | func (l *throttlingListener) pauseTime() time.Duration {
rate := l.connRateMetric()
if rate <= l.lowerThreshold {
return l.minPause
}
if rate >= l.upperThreshold {
return l.maxPause
}
// rate is between min and max so interpolate.
pauseFactor := float64(rate-l.lowerThreshold) / float64(l.upperThreshold-l.lowerThreshold)
return l.minPause + time.Duration(float64(l.maxPause-l.minPause)*pauseFactor)
} | [
"func",
"(",
"l",
"*",
"throttlingListener",
")",
"pauseTime",
"(",
")",
"time",
".",
"Duration",
"{",
"rate",
":=",
"l",
".",
"connRateMetric",
"(",
")",
"\n",
"if",
"rate",
"<=",
"l",
".",
"lowerThreshold",
"{",
"return",
"l",
".",
"minPause",
"\n",
"}",
"\n",
"if",
"rate",
">=",
"l",
".",
"upperThreshold",
"{",
"return",
"l",
".",
"maxPause",
"\n",
"}",
"\n",
"// rate is between min and max so interpolate.",
"pauseFactor",
":=",
"float64",
"(",
"rate",
"-",
"l",
".",
"lowerThreshold",
")",
"/",
"float64",
"(",
"l",
".",
"upperThreshold",
"-",
"l",
".",
"lowerThreshold",
")",
"\n",
"return",
"l",
".",
"minPause",
"+",
"time",
".",
"Duration",
"(",
"float64",
"(",
"l",
".",
"maxPause",
"-",
"l",
".",
"minPause",
")",
"*",
"pauseFactor",
")",
"\n",
"}"
] | // pauseTime returns a time based on rate of connections.
// - up to lowerThreshold, return minPause
// - above to upperThreshold, return maxPause
// - in between, return an interpolated value | [
"pauseTime",
"returns",
"a",
"time",
"based",
"on",
"rate",
"of",
"connections",
".",
"-",
"up",
"to",
"lowerThreshold",
"return",
"minPause",
"-",
"above",
"to",
"upperThreshold",
"return",
"maxPause",
"-",
"in",
"between",
"return",
"an",
"interpolated",
"value"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/listener.go#L113-L124 |
5,098 | juju/juju | cmd/juju/application/unexpose.go | Run | func (c *unexposeCommand) Run(_ *cmd.Context) error {
client, err := c.getAPI()
if err != nil {
return err
}
defer client.Close()
return block.ProcessBlockedError(client.Unexpose(c.ApplicationName), block.BlockChange)
} | go | func (c *unexposeCommand) Run(_ *cmd.Context) error {
client, err := c.getAPI()
if err != nil {
return err
}
defer client.Close()
return block.ProcessBlockedError(client.Unexpose(c.ApplicationName), block.BlockChange)
} | [
"func",
"(",
"c",
"*",
"unexposeCommand",
")",
"Run",
"(",
"_",
"*",
"cmd",
".",
"Context",
")",
"error",
"{",
"client",
",",
"err",
":=",
"c",
".",
"getAPI",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"client",
".",
"Close",
"(",
")",
"\n",
"return",
"block",
".",
"ProcessBlockedError",
"(",
"client",
".",
"Unexpose",
"(",
"c",
".",
"ApplicationName",
")",
",",
"block",
".",
"BlockChange",
")",
"\n",
"}"
] | // Run changes the juju-managed firewall to hide any
// ports that were also explicitly marked by units as closed. | [
"Run",
"changes",
"the",
"juju",
"-",
"managed",
"firewall",
"to",
"hide",
"any",
"ports",
"that",
"were",
"also",
"explicitly",
"marked",
"by",
"units",
"as",
"closed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/application/unexpose.go#L68-L75 |
5,099 | juju/juju | cmd/juju/application/flags.go | Set | func (m stringMap) Set(s string) error {
if *m.mapping == nil {
*m.mapping = map[string]string{}
}
// make a copy so the following code is less ugly with dereferencing.
mapping := *m.mapping
vals := strings.SplitN(s, "=", 2)
if len(vals) != 2 {
return errors.NewNotValid(nil, "badly formatted name value pair: "+s)
}
name, value := vals[0], vals[1]
if _, ok := mapping[name]; ok {
return errors.Errorf("duplicate name specified: %q", name)
}
mapping[name] = value
return nil
} | go | func (m stringMap) Set(s string) error {
if *m.mapping == nil {
*m.mapping = map[string]string{}
}
// make a copy so the following code is less ugly with dereferencing.
mapping := *m.mapping
vals := strings.SplitN(s, "=", 2)
if len(vals) != 2 {
return errors.NewNotValid(nil, "badly formatted name value pair: "+s)
}
name, value := vals[0], vals[1]
if _, ok := mapping[name]; ok {
return errors.Errorf("duplicate name specified: %q", name)
}
mapping[name] = value
return nil
} | [
"func",
"(",
"m",
"stringMap",
")",
"Set",
"(",
"s",
"string",
")",
"error",
"{",
"if",
"*",
"m",
".",
"mapping",
"==",
"nil",
"{",
"*",
"m",
".",
"mapping",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"}",
"\n",
"// make a copy so the following code is less ugly with dereferencing.",
"mapping",
":=",
"*",
"m",
".",
"mapping",
"\n\n",
"vals",
":=",
"strings",
".",
"SplitN",
"(",
"s",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"vals",
")",
"!=",
"2",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"nil",
",",
"\"",
"\"",
"+",
"s",
")",
"\n",
"}",
"\n",
"name",
",",
"value",
":=",
"vals",
"[",
"0",
"]",
",",
"vals",
"[",
"1",
"]",
"\n",
"if",
"_",
",",
"ok",
":=",
"mapping",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"mapping",
"[",
"name",
"]",
"=",
"value",
"\n",
"return",
"nil",
"\n",
"}"
] | // Set implements gnuflag.Value's Set method. | [
"Set",
"implements",
"gnuflag",
".",
"Value",
"s",
"Set",
"method",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/application/flags.go#L176-L193 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.