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
|
---|---|---|---|---|---|---|---|---|---|---|---|
155,000 | juju/juju | worker/uniter/op_callbacks.go | CommitHook | func (opc *operationCallbacks) CommitHook(hi hook.Info) error {
switch {
case hi.Kind.IsRelation():
return opc.u.relations.CommitHook(hi)
case hi.Kind.IsStorage():
return opc.u.storage.CommitHook(hi)
}
return nil
} | go | func (opc *operationCallbacks) CommitHook(hi hook.Info) error {
switch {
case hi.Kind.IsRelation():
return opc.u.relations.CommitHook(hi)
case hi.Kind.IsStorage():
return opc.u.storage.CommitHook(hi)
}
return nil
} | [
"func",
"(",
"opc",
"*",
"operationCallbacks",
")",
"CommitHook",
"(",
"hi",
"hook",
".",
"Info",
")",
"error",
"{",
"switch",
"{",
"case",
"hi",
".",
"Kind",
".",
"IsRelation",
"(",
")",
":",
"return",
"opc",
".",
"u",
".",
"relations",
".",
"CommitHook",
"(",
"hi",
")",
"\n",
"case",
"hi",
".",
"Kind",
".",
"IsStorage",
"(",
")",
":",
"return",
"opc",
".",
"u",
".",
"storage",
".",
"CommitHook",
"(",
"hi",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CommitHook is part of the operation.Callbacks interface. | [
"CommitHook",
"is",
"part",
"of",
"the",
"operation",
".",
"Callbacks",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/op_callbacks.go#L60-L68 |
155,001 | juju/juju | worker/uniter/op_callbacks.go | NotifyHookCompleted | func (opc *operationCallbacks) NotifyHookCompleted(hook string, ctx runner.Context) {
if opc.u.observer != nil {
notifyHook(hook, ctx, opc.u.observer.HookCompleted)
}
} | go | func (opc *operationCallbacks) NotifyHookCompleted(hook string, ctx runner.Context) {
if opc.u.observer != nil {
notifyHook(hook, ctx, opc.u.observer.HookCompleted)
}
} | [
"func",
"(",
"opc",
"*",
"operationCallbacks",
")",
"NotifyHookCompleted",
"(",
"hook",
"string",
",",
"ctx",
"runner",
".",
"Context",
")",
"{",
"if",
"opc",
".",
"u",
".",
"observer",
"!=",
"nil",
"{",
"notifyHook",
"(",
"hook",
",",
"ctx",
",",
"opc",
".",
"u",
".",
"observer",
".",
"HookCompleted",
")",
"\n",
"}",
"\n",
"}"
] | // NotifyHookCompleted is part of the operation.Callbacks interface. | [
"NotifyHookCompleted",
"is",
"part",
"of",
"the",
"operation",
".",
"Callbacks",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/op_callbacks.go#L82-L86 |
155,002 | juju/juju | worker/uniter/op_callbacks.go | NotifyHookFailed | func (opc *operationCallbacks) NotifyHookFailed(hook string, ctx runner.Context) {
if opc.u.observer != nil {
notifyHook(hook, ctx, opc.u.observer.HookFailed)
}
} | go | func (opc *operationCallbacks) NotifyHookFailed(hook string, ctx runner.Context) {
if opc.u.observer != nil {
notifyHook(hook, ctx, opc.u.observer.HookFailed)
}
} | [
"func",
"(",
"opc",
"*",
"operationCallbacks",
")",
"NotifyHookFailed",
"(",
"hook",
"string",
",",
"ctx",
"runner",
".",
"Context",
")",
"{",
"if",
"opc",
".",
"u",
".",
"observer",
"!=",
"nil",
"{",
"notifyHook",
"(",
"hook",
",",
"ctx",
",",
"opc",
".",
"u",
".",
"observer",
".",
"HookFailed",
")",
"\n",
"}",
"\n",
"}"
] | // NotifyHookFailed is part of the operation.Callbacks interface. | [
"NotifyHookFailed",
"is",
"part",
"of",
"the",
"operation",
".",
"Callbacks",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/op_callbacks.go#L89-L93 |
155,003 | juju/juju | worker/uniter/op_callbacks.go | FailAction | func (opc *operationCallbacks) FailAction(actionId, message string) error {
if !names.IsValidAction(actionId) {
return errors.Errorf("invalid action id %q", actionId)
}
tag := names.NewActionTag(actionId)
err := opc.u.st.ActionFinish(tag, params.ActionFailed, nil, message)
if params.IsCodeNotFoundOrCodeUnauthorized(err) {
err = nil
}
return err
} | go | func (opc *operationCallbacks) FailAction(actionId, message string) error {
if !names.IsValidAction(actionId) {
return errors.Errorf("invalid action id %q", actionId)
}
tag := names.NewActionTag(actionId)
err := opc.u.st.ActionFinish(tag, params.ActionFailed, nil, message)
if params.IsCodeNotFoundOrCodeUnauthorized(err) {
err = nil
}
return err
} | [
"func",
"(",
"opc",
"*",
"operationCallbacks",
")",
"FailAction",
"(",
"actionId",
",",
"message",
"string",
")",
"error",
"{",
"if",
"!",
"names",
".",
"IsValidAction",
"(",
"actionId",
")",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"actionId",
")",
"\n",
"}",
"\n",
"tag",
":=",
"names",
".",
"NewActionTag",
"(",
"actionId",
")",
"\n",
"err",
":=",
"opc",
".",
"u",
".",
"st",
".",
"ActionFinish",
"(",
"tag",
",",
"params",
".",
"ActionFailed",
",",
"nil",
",",
"message",
")",
"\n",
"if",
"params",
".",
"IsCodeNotFoundOrCodeUnauthorized",
"(",
"err",
")",
"{",
"err",
"=",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // FailAction is part of the operation.Callbacks interface. | [
"FailAction",
"is",
"part",
"of",
"the",
"operation",
".",
"Callbacks",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/op_callbacks.go#L96-L106 |
155,004 | juju/juju | worker/uniter/op_callbacks.go | GetArchiveInfo | func (opc *operationCallbacks) GetArchiveInfo(charmURL *corecharm.URL) (charm.BundleInfo, error) {
ch, err := opc.u.st.Charm(charmURL)
if err != nil {
return nil, errors.Trace(err)
}
return ch, nil
} | go | func (opc *operationCallbacks) GetArchiveInfo(charmURL *corecharm.URL) (charm.BundleInfo, error) {
ch, err := opc.u.st.Charm(charmURL)
if err != nil {
return nil, errors.Trace(err)
}
return ch, nil
} | [
"func",
"(",
"opc",
"*",
"operationCallbacks",
")",
"GetArchiveInfo",
"(",
"charmURL",
"*",
"corecharm",
".",
"URL",
")",
"(",
"charm",
".",
"BundleInfo",
",",
"error",
")",
"{",
"ch",
",",
"err",
":=",
"opc",
".",
"u",
".",
"st",
".",
"Charm",
"(",
"charmURL",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"ch",
",",
"nil",
"\n",
"}"
] | // GetArchiveInfo is part of the operation.Callbacks interface. | [
"GetArchiveInfo",
"is",
"part",
"of",
"the",
"operation",
".",
"Callbacks",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/op_callbacks.go#L109-L115 |
155,005 | juju/juju | worker/uniter/op_callbacks.go | SetCurrentCharm | func (opc *operationCallbacks) SetCurrentCharm(charmURL *corecharm.URL) error {
return opc.u.unit.SetCharmURL(charmURL)
} | go | func (opc *operationCallbacks) SetCurrentCharm(charmURL *corecharm.URL) error {
return opc.u.unit.SetCharmURL(charmURL)
} | [
"func",
"(",
"opc",
"*",
"operationCallbacks",
")",
"SetCurrentCharm",
"(",
"charmURL",
"*",
"corecharm",
".",
"URL",
")",
"error",
"{",
"return",
"opc",
".",
"u",
".",
"unit",
".",
"SetCharmURL",
"(",
"charmURL",
")",
"\n",
"}"
] | // SetCurrentCharm is part of the operation.Callbacks interface. | [
"SetCurrentCharm",
"is",
"part",
"of",
"the",
"operation",
".",
"Callbacks",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/op_callbacks.go#L118-L120 |
155,006 | juju/juju | worker/uniter/op_callbacks.go | SetExecutingStatus | func (opc *operationCallbacks) SetExecutingStatus(message string) error {
return setAgentStatus(opc.u, status.Executing, message, nil)
} | go | func (opc *operationCallbacks) SetExecutingStatus(message string) error {
return setAgentStatus(opc.u, status.Executing, message, nil)
} | [
"func",
"(",
"opc",
"*",
"operationCallbacks",
")",
"SetExecutingStatus",
"(",
"message",
"string",
")",
"error",
"{",
"return",
"setAgentStatus",
"(",
"opc",
".",
"u",
",",
"status",
".",
"Executing",
",",
"message",
",",
"nil",
")",
"\n",
"}"
] | // SetExecutingStatus is part of the operation.Callbacks interface. | [
"SetExecutingStatus",
"is",
"part",
"of",
"the",
"operation",
".",
"Callbacks",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/op_callbacks.go#L123-L125 |
155,007 | juju/juju | worker/uniter/op_callbacks.go | SetUpgradeSeriesStatus | func (opc *operationCallbacks) SetUpgradeSeriesStatus(upgradeSeriesStatus model.UpgradeSeriesStatus, reason string) error {
return setUpgradeSeriesStatus(opc.u, upgradeSeriesStatus, reason)
} | go | func (opc *operationCallbacks) SetUpgradeSeriesStatus(upgradeSeriesStatus model.UpgradeSeriesStatus, reason string) error {
return setUpgradeSeriesStatus(opc.u, upgradeSeriesStatus, reason)
} | [
"func",
"(",
"opc",
"*",
"operationCallbacks",
")",
"SetUpgradeSeriesStatus",
"(",
"upgradeSeriesStatus",
"model",
".",
"UpgradeSeriesStatus",
",",
"reason",
"string",
")",
"error",
"{",
"return",
"setUpgradeSeriesStatus",
"(",
"opc",
".",
"u",
",",
"upgradeSeriesStatus",
",",
"reason",
")",
"\n",
"}"
] | // SetUpgradeSeriesStatus is part of the operation.Callbacks interface. | [
"SetUpgradeSeriesStatus",
"is",
"part",
"of",
"the",
"operation",
".",
"Callbacks",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/uniter/op_callbacks.go#L128-L130 |
155,008 | juju/juju | provider/openstack/storage.go | makeContainer | func (s *openstackstorage) makeContainer(containerName string, containerACL swift.ACL) error {
s.Lock()
defer s.Unlock()
if s.madeContainer {
return nil
}
// try to make the container - CreateContainer will succeed if the container already exists.
err := s.swift.CreateContainer(containerName, containerACL)
if err == nil {
s.madeContainer = true
}
return err
} | go | func (s *openstackstorage) makeContainer(containerName string, containerACL swift.ACL) error {
s.Lock()
defer s.Unlock()
if s.madeContainer {
return nil
}
// try to make the container - CreateContainer will succeed if the container already exists.
err := s.swift.CreateContainer(containerName, containerACL)
if err == nil {
s.madeContainer = true
}
return err
} | [
"func",
"(",
"s",
"*",
"openstackstorage",
")",
"makeContainer",
"(",
"containerName",
"string",
",",
"containerACL",
"swift",
".",
"ACL",
")",
"error",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"if",
"s",
".",
"madeContainer",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"// try to make the container - CreateContainer will succeed if the container already exists.",
"err",
":=",
"s",
".",
"swift",
".",
"CreateContainer",
"(",
"containerName",
",",
"containerACL",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"s",
".",
"madeContainer",
"=",
"true",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // makeContainer makes the environment's control container, the
// place where bootstrap information and deployed charms
// are stored. To avoid two round trips on every PUT operation,
// we do this only once for each environ. | [
"makeContainer",
"makes",
"the",
"environment",
"s",
"control",
"container",
"the",
"place",
"where",
"bootstrap",
"information",
"and",
"deployed",
"charms",
"are",
"stored",
".",
"To",
"avoid",
"two",
"round",
"trips",
"on",
"every",
"PUT",
"operation",
"we",
"do",
"this",
"only",
"once",
"for",
"each",
"environ",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/openstack/storage.go#L33-L45 |
155,009 | juju/juju | provider/openstack/storage.go | ShouldRetry | func (s *openstackstorage) ShouldRetry(err error) bool {
_, retry := maybeNotFound(err)
return retry
} | go | func (s *openstackstorage) ShouldRetry(err error) bool {
_, retry := maybeNotFound(err)
return retry
} | [
"func",
"(",
"s",
"*",
"openstackstorage",
")",
"ShouldRetry",
"(",
"err",
"error",
")",
"bool",
"{",
"_",
",",
"retry",
":=",
"maybeNotFound",
"(",
"err",
")",
"\n",
"return",
"retry",
"\n",
"}"
] | // ShouldRetry is specified in the StorageReader interface. | [
"ShouldRetry",
"is",
"specified",
"in",
"the",
"StorageReader",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/openstack/storage.go#L85-L88 |
155,010 | juju/juju | provider/openstack/storage.go | RemoveAll | func (s *openstackstorage) RemoveAll() error {
names, err := storage.List(s, "")
if err != nil {
return err
}
// Remove all the objects in parallel so as to minimize round-trips.
// Start with a goroutine feeding all the names that need to be
// deleted.
toDelete := make(chan string)
go func() {
for _, name := range names {
toDelete <- name
}
close(toDelete)
}()
// Now spawn up to N routines to actually issue the requests.
maxRoutines := len(names)
if maxConcurrentDeletes < maxRoutines {
maxRoutines = maxConcurrentDeletes
}
var wg sync.WaitGroup
wg.Add(maxRoutines)
// Make a channel long enough to buffer all possible errors.
errc := make(chan error, len(names))
for i := 0; i < maxRoutines; i++ {
go func() {
for name := range toDelete {
if err := s.Remove(name); err != nil {
errc <- err
}
}
wg.Done()
}()
}
wg.Wait()
select {
case err := <-errc:
return fmt.Errorf("cannot delete all provider state: %v", err)
default:
}
s.Lock()
defer s.Unlock()
// Even DeleteContainer fails, it won't harm if we try again - the
// operation might have succeeded even if we get an error.
s.madeContainer = false
err = s.swift.DeleteContainer(s.containerName)
err, ok := maybeNotFound(err)
if ok {
return nil
}
return err
} | go | func (s *openstackstorage) RemoveAll() error {
names, err := storage.List(s, "")
if err != nil {
return err
}
// Remove all the objects in parallel so as to minimize round-trips.
// Start with a goroutine feeding all the names that need to be
// deleted.
toDelete := make(chan string)
go func() {
for _, name := range names {
toDelete <- name
}
close(toDelete)
}()
// Now spawn up to N routines to actually issue the requests.
maxRoutines := len(names)
if maxConcurrentDeletes < maxRoutines {
maxRoutines = maxConcurrentDeletes
}
var wg sync.WaitGroup
wg.Add(maxRoutines)
// Make a channel long enough to buffer all possible errors.
errc := make(chan error, len(names))
for i := 0; i < maxRoutines; i++ {
go func() {
for name := range toDelete {
if err := s.Remove(name); err != nil {
errc <- err
}
}
wg.Done()
}()
}
wg.Wait()
select {
case err := <-errc:
return fmt.Errorf("cannot delete all provider state: %v", err)
default:
}
s.Lock()
defer s.Unlock()
// Even DeleteContainer fails, it won't harm if we try again - the
// operation might have succeeded even if we get an error.
s.madeContainer = false
err = s.swift.DeleteContainer(s.containerName)
err, ok := maybeNotFound(err)
if ok {
return nil
}
return err
} | [
"func",
"(",
"s",
"*",
"openstackstorage",
")",
"RemoveAll",
"(",
")",
"error",
"{",
"names",
",",
"err",
":=",
"storage",
".",
"List",
"(",
"s",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// Remove all the objects in parallel so as to minimize round-trips.",
"// Start with a goroutine feeding all the names that need to be",
"// deleted.",
"toDelete",
":=",
"make",
"(",
"chan",
"string",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"for",
"_",
",",
"name",
":=",
"range",
"names",
"{",
"toDelete",
"<-",
"name",
"\n",
"}",
"\n",
"close",
"(",
"toDelete",
")",
"\n",
"}",
"(",
")",
"\n",
"// Now spawn up to N routines to actually issue the requests.",
"maxRoutines",
":=",
"len",
"(",
"names",
")",
"\n",
"if",
"maxConcurrentDeletes",
"<",
"maxRoutines",
"{",
"maxRoutines",
"=",
"maxConcurrentDeletes",
"\n",
"}",
"\n",
"var",
"wg",
"sync",
".",
"WaitGroup",
"\n",
"wg",
".",
"Add",
"(",
"maxRoutines",
")",
"\n",
"// Make a channel long enough to buffer all possible errors.",
"errc",
":=",
"make",
"(",
"chan",
"error",
",",
"len",
"(",
"names",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"maxRoutines",
";",
"i",
"++",
"{",
"go",
"func",
"(",
")",
"{",
"for",
"name",
":=",
"range",
"toDelete",
"{",
"if",
"err",
":=",
"s",
".",
"Remove",
"(",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"errc",
"<-",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"wg",
".",
"Done",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"select",
"{",
"case",
"err",
":=",
"<-",
"errc",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"default",
":",
"}",
"\n\n",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"// Even DeleteContainer fails, it won't harm if we try again - the",
"// operation might have succeeded even if we get an error.",
"s",
".",
"madeContainer",
"=",
"false",
"\n",
"err",
"=",
"s",
".",
"swift",
".",
"DeleteContainer",
"(",
"s",
".",
"containerName",
")",
"\n",
"err",
",",
"ok",
":=",
"maybeNotFound",
"(",
"err",
")",
"\n",
"if",
"ok",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // RemoveAll is specified in the StorageWriter interface. | [
"RemoveAll",
"is",
"specified",
"in",
"the",
"StorageWriter",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/openstack/storage.go#L128-L180 |
155,011 | juju/juju | provider/openstack/storage.go | maybeNotFound | func maybeNotFound(err error) (error, bool) {
if err != nil && gooseerrors.IsNotFound(err) {
return jujuerrors.NewNotFound(err, ""), true
}
return err, false
} | go | func maybeNotFound(err error) (error, bool) {
if err != nil && gooseerrors.IsNotFound(err) {
return jujuerrors.NewNotFound(err, ""), true
}
return err, false
} | [
"func",
"maybeNotFound",
"(",
"err",
"error",
")",
"(",
"error",
",",
"bool",
")",
"{",
"if",
"err",
"!=",
"nil",
"&&",
"gooseerrors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"jujuerrors",
".",
"NewNotFound",
"(",
"err",
",",
"\"",
"\"",
")",
",",
"true",
"\n",
"}",
"\n",
"return",
"err",
",",
"false",
"\n",
"}"
] | // maybeNotFound returns a errors.NotFoundError if the root cause of the specified error is due to a file or
// container not being found. | [
"maybeNotFound",
"returns",
"a",
"errors",
".",
"NotFoundError",
"if",
"the",
"root",
"cause",
"of",
"the",
"specified",
"error",
"is",
"due",
"to",
"a",
"file",
"or",
"container",
"not",
"being",
"found",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/openstack/storage.go#L184-L189 |
155,012 | juju/juju | jujuclient/accounts.go | ReadAccountsFile | func ReadAccountsFile(file string) (map[string]AccountDetails, error) {
data, err := ioutil.ReadFile(file)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
accounts, err := ParseAccounts(data)
if err != nil {
return nil, err
}
if err := migrateLocalAccountUsers(accounts); err != nil {
return nil, err
}
return accounts, nil
} | go | func ReadAccountsFile(file string) (map[string]AccountDetails, error) {
data, err := ioutil.ReadFile(file)
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
accounts, err := ParseAccounts(data)
if err != nil {
return nil, err
}
if err := migrateLocalAccountUsers(accounts); err != nil {
return nil, err
}
return accounts, nil
} | [
"func",
"ReadAccountsFile",
"(",
"file",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"AccountDetails",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"file",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"accounts",
",",
"err",
":=",
"ParseAccounts",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"migrateLocalAccountUsers",
"(",
"accounts",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"accounts",
",",
"nil",
"\n",
"}"
] | // ReadAccountsFile loads all accounts defined in a given file.
// If the file is not found, it is not an error. | [
"ReadAccountsFile",
"loads",
"all",
"accounts",
"defined",
"in",
"a",
"given",
"file",
".",
"If",
"the",
"file",
"is",
"not",
"found",
"it",
"is",
"not",
"an",
"error",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/accounts.go#L27-L43 |
155,013 | juju/juju | jujuclient/accounts.go | WriteAccountsFile | func WriteAccountsFile(controllerAccounts map[string]AccountDetails) error {
data, err := yaml.Marshal(accountsCollection{controllerAccounts})
if err != nil {
return errors.Annotate(err, "cannot marshal accounts")
}
return utils.AtomicWriteFile(JujuAccountsPath(), data, os.FileMode(0600))
} | go | func WriteAccountsFile(controllerAccounts map[string]AccountDetails) error {
data, err := yaml.Marshal(accountsCollection{controllerAccounts})
if err != nil {
return errors.Annotate(err, "cannot marshal accounts")
}
return utils.AtomicWriteFile(JujuAccountsPath(), data, os.FileMode(0600))
} | [
"func",
"WriteAccountsFile",
"(",
"controllerAccounts",
"map",
"[",
"string",
"]",
"AccountDetails",
")",
"error",
"{",
"data",
",",
"err",
":=",
"yaml",
".",
"Marshal",
"(",
"accountsCollection",
"{",
"controllerAccounts",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"utils",
".",
"AtomicWriteFile",
"(",
"JujuAccountsPath",
"(",
")",
",",
"data",
",",
"os",
".",
"FileMode",
"(",
"0600",
")",
")",
"\n",
"}"
] | // WriteAccountsFile marshals to YAML details of the given accounts
// and writes it to the accounts file. | [
"WriteAccountsFile",
"marshals",
"to",
"YAML",
"details",
"of",
"the",
"given",
"accounts",
"and",
"writes",
"it",
"to",
"the",
"accounts",
"file",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/accounts.go#L65-L71 |
155,014 | juju/juju | jujuclient/accounts.go | ParseAccounts | func ParseAccounts(data []byte) (map[string]AccountDetails, error) {
var result accountsCollection
if err := yaml.Unmarshal(data, &result); err != nil {
return nil, errors.Annotate(err, "cannot unmarshal accounts")
}
return result.ControllerAccounts, nil
} | go | func ParseAccounts(data []byte) (map[string]AccountDetails, error) {
var result accountsCollection
if err := yaml.Unmarshal(data, &result); err != nil {
return nil, errors.Annotate(err, "cannot unmarshal accounts")
}
return result.ControllerAccounts, nil
} | [
"func",
"ParseAccounts",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"map",
"[",
"string",
"]",
"AccountDetails",
",",
"error",
")",
"{",
"var",
"result",
"accountsCollection",
"\n",
"if",
"err",
":=",
"yaml",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"result",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"result",
".",
"ControllerAccounts",
",",
"nil",
"\n",
"}"
] | // ParseAccounts parses the given YAML bytes into accounts metadata. | [
"ParseAccounts",
"parses",
"the",
"given",
"YAML",
"bytes",
"into",
"accounts",
"metadata",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/jujuclient/accounts.go#L74-L80 |
155,015 | juju/juju | provider/azure/internal/azurecli/az.go | exec | func (a AzureCLI) exec(cmd string, args []string) ([]byte, error) {
var out []byte
var err error
if a.Exec != nil {
out, err = a.Exec(cmd, args)
} else {
out, err = exec.Command(cmd, args...).Output()
}
if exitError, ok := errors.Cause(err).(*exec.ExitError); ok {
err = &Error{
ExitError: *exitError,
}
}
return out, err
} | go | func (a AzureCLI) exec(cmd string, args []string) ([]byte, error) {
var out []byte
var err error
if a.Exec != nil {
out, err = a.Exec(cmd, args)
} else {
out, err = exec.Command(cmd, args...).Output()
}
if exitError, ok := errors.Cause(err).(*exec.ExitError); ok {
err = &Error{
ExitError: *exitError,
}
}
return out, err
} | [
"func",
"(",
"a",
"AzureCLI",
")",
"exec",
"(",
"cmd",
"string",
",",
"args",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"out",
"[",
"]",
"byte",
"\n",
"var",
"err",
"error",
"\n",
"if",
"a",
".",
"Exec",
"!=",
"nil",
"{",
"out",
",",
"err",
"=",
"a",
".",
"Exec",
"(",
"cmd",
",",
"args",
")",
"\n",
"}",
"else",
"{",
"out",
",",
"err",
"=",
"exec",
".",
"Command",
"(",
"cmd",
",",
"args",
"...",
")",
".",
"Output",
"(",
")",
"\n",
"}",
"\n",
"if",
"exitError",
",",
"ok",
":=",
"errors",
".",
"Cause",
"(",
"err",
")",
".",
"(",
"*",
"exec",
".",
"ExitError",
")",
";",
"ok",
"{",
"err",
"=",
"&",
"Error",
"{",
"ExitError",
":",
"*",
"exitError",
",",
"}",
"\n",
"}",
"\n",
"return",
"out",
",",
"err",
"\n",
"}"
] | // exec runs the given command using Exec if specified, or
// os.exec.Command. | [
"exec",
"runs",
"the",
"given",
"command",
"using",
"Exec",
"if",
"specified",
"or",
"os",
".",
"exec",
".",
"Command",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurecli/az.go#L48-L62 |
155,016 | juju/juju | provider/azure/internal/azurecli/az.go | run | func (a AzureCLI) run(v interface{}, args ...string) error {
args = append(args, "-o", "json")
logger.Debugf("running az %s", strings.Join(args, " "))
b, err := a.exec("az", args)
if err != nil {
return errors.Annotate(err, "execution failure")
}
if err := json.Unmarshal(b, v); err != nil {
return errors.Annotate(err, "cannot unmarshal output")
}
return nil
} | go | func (a AzureCLI) run(v interface{}, args ...string) error {
args = append(args, "-o", "json")
logger.Debugf("running az %s", strings.Join(args, " "))
b, err := a.exec("az", args)
if err != nil {
return errors.Annotate(err, "execution failure")
}
if err := json.Unmarshal(b, v); err != nil {
return errors.Annotate(err, "cannot unmarshal output")
}
return nil
} | [
"func",
"(",
"a",
"AzureCLI",
")",
"run",
"(",
"v",
"interface",
"{",
"}",
",",
"args",
"...",
"string",
")",
"error",
"{",
"args",
"=",
"append",
"(",
"args",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"args",
",",
"\"",
"\"",
")",
")",
"\n",
"b",
",",
"err",
":=",
"a",
".",
"exec",
"(",
"\"",
"\"",
",",
"args",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"b",
",",
"v",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // run attempts to execute "az" with the given arguments. Unmarshalling
// the json output into v. | [
"run",
"attempts",
"to",
"execute",
"az",
"with",
"the",
"given",
"arguments",
".",
"Unmarshalling",
"the",
"json",
"output",
"into",
"v",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurecli/az.go#L66-L77 |
155,017 | juju/juju | provider/azure/internal/azurecli/az.go | Token | func (t AccessToken) Token() *adal.Token {
return &adal.Token{
AccessToken: t.AccessToken,
Type: t.TokenType,
}
} | go | func (t AccessToken) Token() *adal.Token {
return &adal.Token{
AccessToken: t.AccessToken,
Type: t.TokenType,
}
} | [
"func",
"(",
"t",
"AccessToken",
")",
"Token",
"(",
")",
"*",
"adal",
".",
"Token",
"{",
"return",
"&",
"adal",
".",
"Token",
"{",
"AccessToken",
":",
"t",
".",
"AccessToken",
",",
"Type",
":",
"t",
".",
"TokenType",
",",
"}",
"\n",
"}"
] | // Token creates an adal.Token from the AccessToken. This token can be
// used with go-autorest to access azure endpoints. | [
"Token",
"creates",
"an",
"adal",
".",
"Token",
"from",
"the",
"AccessToken",
".",
"This",
"token",
"can",
"be",
"used",
"with",
"go",
"-",
"autorest",
"to",
"access",
"azure",
"endpoints",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurecli/az.go#L90-L95 |
155,018 | juju/juju | provider/azure/internal/azurecli/az.go | GetAccessToken | func (a AzureCLI) GetAccessToken(subscription, resource string) (*AccessToken, error) {
cmd := []string{"account", "get-access-token"}
if subscription != "" {
cmd = append(cmd, "--subscription", subscription)
}
if resource != "" {
cmd = append(cmd, "--resource", resource)
}
var tok AccessToken
if err := a.run(&tok, cmd...); err != nil {
return nil, errors.Trace(err)
}
return &tok, nil
} | go | func (a AzureCLI) GetAccessToken(subscription, resource string) (*AccessToken, error) {
cmd := []string{"account", "get-access-token"}
if subscription != "" {
cmd = append(cmd, "--subscription", subscription)
}
if resource != "" {
cmd = append(cmd, "--resource", resource)
}
var tok AccessToken
if err := a.run(&tok, cmd...); err != nil {
return nil, errors.Trace(err)
}
return &tok, nil
} | [
"func",
"(",
"a",
"AzureCLI",
")",
"GetAccessToken",
"(",
"subscription",
",",
"resource",
"string",
")",
"(",
"*",
"AccessToken",
",",
"error",
")",
"{",
"cmd",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"if",
"subscription",
"!=",
"\"",
"\"",
"{",
"cmd",
"=",
"append",
"(",
"cmd",
",",
"\"",
"\"",
",",
"subscription",
")",
"\n",
"}",
"\n",
"if",
"resource",
"!=",
"\"",
"\"",
"{",
"cmd",
"=",
"append",
"(",
"cmd",
",",
"\"",
"\"",
",",
"resource",
")",
"\n",
"}",
"\n",
"var",
"tok",
"AccessToken",
"\n",
"if",
"err",
":=",
"a",
".",
"run",
"(",
"&",
"tok",
",",
"cmd",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"tok",
",",
"nil",
"\n",
"}"
] | // GetAccessToken gets an access token from the Azure CLI to access the
// given resource using the given subscription. Either subscription or
// resource may be empty in which case the default from the az
// application are used. | [
"GetAccessToken",
"gets",
"an",
"access",
"token",
"from",
"the",
"Azure",
"CLI",
"to",
"access",
"the",
"given",
"resource",
"using",
"the",
"given",
"subscription",
".",
"Either",
"subscription",
"or",
"resource",
"may",
"be",
"empty",
"in",
"which",
"case",
"the",
"default",
"from",
"the",
"az",
"application",
"are",
"used",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurecli/az.go#L101-L114 |
155,019 | juju/juju | provider/azure/internal/azurecli/az.go | ShowAccount | func (a AzureCLI) ShowAccount(subscription string) (*Account, error) {
cmd := []string{"account", "show"}
if subscription != "" {
cmd = append(cmd, "--subscription", subscription)
}
var acc showAccount
if err := a.run(&acc, cmd...); err != nil {
return nil, errors.Trace(err)
}
if acc.Account.CloudName == "" {
acc.Account.CloudName = acc.EnvironmentName
}
return &acc.Account, nil
} | go | func (a AzureCLI) ShowAccount(subscription string) (*Account, error) {
cmd := []string{"account", "show"}
if subscription != "" {
cmd = append(cmd, "--subscription", subscription)
}
var acc showAccount
if err := a.run(&acc, cmd...); err != nil {
return nil, errors.Trace(err)
}
if acc.Account.CloudName == "" {
acc.Account.CloudName = acc.EnvironmentName
}
return &acc.Account, nil
} | [
"func",
"(",
"a",
"AzureCLI",
")",
"ShowAccount",
"(",
"subscription",
"string",
")",
"(",
"*",
"Account",
",",
"error",
")",
"{",
"cmd",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"if",
"subscription",
"!=",
"\"",
"\"",
"{",
"cmd",
"=",
"append",
"(",
"cmd",
",",
"\"",
"\"",
",",
"subscription",
")",
"\n",
"}",
"\n",
"var",
"acc",
"showAccount",
"\n",
"if",
"err",
":=",
"a",
".",
"run",
"(",
"&",
"acc",
",",
"cmd",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"acc",
".",
"Account",
".",
"CloudName",
"==",
"\"",
"\"",
"{",
"acc",
".",
"Account",
".",
"CloudName",
"=",
"acc",
".",
"EnvironmentName",
"\n",
"}",
"\n",
"return",
"&",
"acc",
".",
"Account",
",",
"nil",
"\n",
"}"
] | // ShowAccount returns the account details for the account with the given
// subscription ID. If the subscription is empty then the default Azure
// CLI account is returned. | [
"ShowAccount",
"returns",
"the",
"account",
"details",
"for",
"the",
"account",
"with",
"the",
"given",
"subscription",
"ID",
".",
"If",
"the",
"subscription",
"is",
"empty",
"then",
"the",
"default",
"Azure",
"CLI",
"account",
"is",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurecli/az.go#L136-L149 |
155,020 | juju/juju | provider/azure/internal/azurecli/az.go | ListAccounts | func (a AzureCLI) ListAccounts() ([]Account, error) {
var accounts []Account
if err := a.run(&accounts, "account", "list"); err != nil {
return nil, errors.Trace(err)
}
return accounts, nil
} | go | func (a AzureCLI) ListAccounts() ([]Account, error) {
var accounts []Account
if err := a.run(&accounts, "account", "list"); err != nil {
return nil, errors.Trace(err)
}
return accounts, nil
} | [
"func",
"(",
"a",
"AzureCLI",
")",
"ListAccounts",
"(",
")",
"(",
"[",
"]",
"Account",
",",
"error",
")",
"{",
"var",
"accounts",
"[",
"]",
"Account",
"\n",
"if",
"err",
":=",
"a",
".",
"run",
"(",
"&",
"accounts",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"accounts",
",",
"nil",
"\n",
"}"
] | // ListAccounts returns the details for all accounts available in the
// Azure CLI. | [
"ListAccounts",
"returns",
"the",
"details",
"for",
"all",
"accounts",
"available",
"in",
"the",
"Azure",
"CLI",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurecli/az.go#L153-L159 |
155,021 | juju/juju | provider/azure/internal/azurecli/az.go | FindAccountsWithCloudName | func (a AzureCLI) FindAccountsWithCloudName(name string) ([]Account, error) {
var accounts []Account
cmd := []string{
"account",
"list",
"--query", fmt.Sprintf("[?cloudName=='%s']", name),
}
if err := a.run(&accounts, cmd...); err != nil {
return nil, errors.Trace(err)
}
return accounts, nil
} | go | func (a AzureCLI) FindAccountsWithCloudName(name string) ([]Account, error) {
var accounts []Account
cmd := []string{
"account",
"list",
"--query", fmt.Sprintf("[?cloudName=='%s']", name),
}
if err := a.run(&accounts, cmd...); err != nil {
return nil, errors.Trace(err)
}
return accounts, nil
} | [
"func",
"(",
"a",
"AzureCLI",
")",
"FindAccountsWithCloudName",
"(",
"name",
"string",
")",
"(",
"[",
"]",
"Account",
",",
"error",
")",
"{",
"var",
"accounts",
"[",
"]",
"Account",
"\n",
"cmd",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"name",
")",
",",
"}",
"\n",
"if",
"err",
":=",
"a",
".",
"run",
"(",
"&",
"accounts",
",",
"cmd",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"accounts",
",",
"nil",
"\n",
"}"
] | // FindAccountsWithCloudName returns the details for all accounts with
// the given cloud name.. | [
"FindAccountsWithCloudName",
"returns",
"the",
"details",
"for",
"all",
"accounts",
"with",
"the",
"given",
"cloud",
"name",
".."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurecli/az.go#L163-L174 |
155,022 | juju/juju | provider/azure/internal/azurecli/az.go | ShowCloud | func (a AzureCLI) ShowCloud(name string) (*Cloud, error) {
cmd := []string{"cloud", "show"}
if name != "" {
cmd = append(cmd, "--name", name)
}
var cloud Cloud
if err := a.run(&cloud, cmd...); err != nil {
return nil, err
}
return &cloud, nil
} | go | func (a AzureCLI) ShowCloud(name string) (*Cloud, error) {
cmd := []string{"cloud", "show"}
if name != "" {
cmd = append(cmd, "--name", name)
}
var cloud Cloud
if err := a.run(&cloud, cmd...); err != nil {
return nil, err
}
return &cloud, nil
} | [
"func",
"(",
"a",
"AzureCLI",
")",
"ShowCloud",
"(",
"name",
"string",
")",
"(",
"*",
"Cloud",
",",
"error",
")",
"{",
"cmd",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"\n",
"if",
"name",
"!=",
"\"",
"\"",
"{",
"cmd",
"=",
"append",
"(",
"cmd",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"var",
"cloud",
"Cloud",
"\n",
"if",
"err",
":=",
"a",
".",
"run",
"(",
"&",
"cloud",
",",
"cmd",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"cloud",
",",
"nil",
"\n",
"}"
] | // ShowCloud returns the details of the cloud with the given name. If the
// name is empty then the details of the default cloud will be returned. | [
"ShowCloud",
"returns",
"the",
"details",
"of",
"the",
"cloud",
"with",
"the",
"given",
"name",
".",
"If",
"the",
"name",
"is",
"empty",
"then",
"the",
"details",
"of",
"the",
"default",
"cloud",
"will",
"be",
"returned",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurecli/az.go#L207-L217 |
155,023 | juju/juju | provider/azure/internal/azurecli/az.go | FindCloudsWithResourceManagerEndpoint | func (a AzureCLI) FindCloudsWithResourceManagerEndpoint(url string) ([]Cloud, error) {
var clouds []Cloud
cmd := []string{
"cloud",
"list",
"--query",
fmt.Sprintf("[?endpoints.resourceManager=='%s']", url),
}
if err := a.run(&clouds, cmd...); err != nil {
return nil, err
}
return clouds, nil
} | go | func (a AzureCLI) FindCloudsWithResourceManagerEndpoint(url string) ([]Cloud, error) {
var clouds []Cloud
cmd := []string{
"cloud",
"list",
"--query",
fmt.Sprintf("[?endpoints.resourceManager=='%s']", url),
}
if err := a.run(&clouds, cmd...); err != nil {
return nil, err
}
return clouds, nil
} | [
"func",
"(",
"a",
"AzureCLI",
")",
"FindCloudsWithResourceManagerEndpoint",
"(",
"url",
"string",
")",
"(",
"[",
"]",
"Cloud",
",",
"error",
")",
"{",
"var",
"clouds",
"[",
"]",
"Cloud",
"\n",
"cmd",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"url",
")",
",",
"}",
"\n",
"if",
"err",
":=",
"a",
".",
"run",
"(",
"&",
"clouds",
",",
"cmd",
"...",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"clouds",
",",
"nil",
"\n",
"}"
] | // FindCloudsWithResourceManagerEndpoint returns a list of clouds which
// use the given url for it's resource manager endpoint. | [
"FindCloudsWithResourceManagerEndpoint",
"returns",
"a",
"list",
"of",
"clouds",
"which",
"use",
"the",
"given",
"url",
"for",
"it",
"s",
"resource",
"manager",
"endpoint",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurecli/az.go#L221-L233 |
155,024 | juju/juju | provider/azure/internal/azurecli/az.go | ListClouds | func (a AzureCLI) ListClouds() ([]Cloud, error) {
var clouds []Cloud
if err := a.run(&clouds, "cloud", "list"); err != nil {
return nil, errors.Trace(err)
}
return clouds, nil
} | go | func (a AzureCLI) ListClouds() ([]Cloud, error) {
var clouds []Cloud
if err := a.run(&clouds, "cloud", "list"); err != nil {
return nil, errors.Trace(err)
}
return clouds, nil
} | [
"func",
"(",
"a",
"AzureCLI",
")",
"ListClouds",
"(",
")",
"(",
"[",
"]",
"Cloud",
",",
"error",
")",
"{",
"var",
"clouds",
"[",
"]",
"Cloud",
"\n",
"if",
"err",
":=",
"a",
".",
"run",
"(",
"&",
"clouds",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"clouds",
",",
"nil",
"\n",
"}"
] | // ListClouds returns the details for all clouds available in the Azure
// CLI. | [
"ListClouds",
"returns",
"the",
"details",
"for",
"all",
"clouds",
"available",
"in",
"the",
"Azure",
"CLI",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/azure/internal/azurecli/az.go#L237-L243 |
155,025 | juju/juju | apiserver/params/status.go | IsEmpty | func (fs *FullStatus) IsEmpty() bool {
return len(fs.Applications) == 0 &&
len(fs.Machines) == 0 &&
len(fs.Offers) == 0 &&
len(fs.RemoteApplications) == 0 &&
len(fs.Relations) == 0
} | go | func (fs *FullStatus) IsEmpty() bool {
return len(fs.Applications) == 0 &&
len(fs.Machines) == 0 &&
len(fs.Offers) == 0 &&
len(fs.RemoteApplications) == 0 &&
len(fs.Relations) == 0
} | [
"func",
"(",
"fs",
"*",
"FullStatus",
")",
"IsEmpty",
"(",
")",
"bool",
"{",
"return",
"len",
"(",
"fs",
".",
"Applications",
")",
"==",
"0",
"&&",
"len",
"(",
"fs",
".",
"Machines",
")",
"==",
"0",
"&&",
"len",
"(",
"fs",
".",
"Offers",
")",
"==",
"0",
"&&",
"len",
"(",
"fs",
".",
"RemoteApplications",
")",
"==",
"0",
"&&",
"len",
"(",
"fs",
".",
"Relations",
")",
"==",
"0",
"\n",
"}"
] | // IsEmpty checks all collections on FullStatus to determine if the status is empty.
// Note that only the collections are checked here as Model information will always be populated. | [
"IsEmpty",
"checks",
"all",
"collections",
"on",
"FullStatus",
"to",
"determine",
"if",
"the",
"status",
"is",
"empty",
".",
"Note",
"that",
"only",
"the",
"collections",
"are",
"checked",
"here",
"as",
"Model",
"information",
"will",
"always",
"be",
"populated",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/params/status.go#L36-L42 |
155,026 | juju/juju | environs/imagedownloads/simplestreams.go | DefaultSource | func DefaultSource() simplestreams.DataSource {
ubuntuImagesURL := imagemetadata.UbuntuCloudImagesURL + "/" + imagemetadata.ReleasedImagesPath
return newDataSourceFunc(ubuntuImagesURL)()
} | go | func DefaultSource() simplestreams.DataSource {
ubuntuImagesURL := imagemetadata.UbuntuCloudImagesURL + "/" + imagemetadata.ReleasedImagesPath
return newDataSourceFunc(ubuntuImagesURL)()
} | [
"func",
"DefaultSource",
"(",
")",
"simplestreams",
".",
"DataSource",
"{",
"ubuntuImagesURL",
":=",
"imagemetadata",
".",
"UbuntuCloudImagesURL",
"+",
"\"",
"\"",
"+",
"imagemetadata",
".",
"ReleasedImagesPath",
"\n",
"return",
"newDataSourceFunc",
"(",
"ubuntuImagesURL",
")",
"(",
")",
"\n",
"}"
] | // DefaultSource creates a new signed simplestreams datasource for use with the
// image-downloads datatype. | [
"DefaultSource",
"creates",
"a",
"new",
"signed",
"simplestreams",
"datasource",
"for",
"use",
"with",
"the",
"image",
"-",
"downloads",
"datatype",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/imagedownloads/simplestreams.go#L31-L34 |
155,027 | juju/juju | environs/imagedownloads/simplestreams.go | newDataSourceFunc | func newDataSourceFunc(baseURL string) func() simplestreams.DataSource {
return func() simplestreams.DataSource {
return simplestreams.NewURLSignedDataSource(
"ubuntu cloud images",
baseURL,
imagemetadata.SimplestreamsImagesPublicKey,
utils.VerifySSLHostnames,
simplestreams.DEFAULT_CLOUD_DATA,
true)
}
} | go | func newDataSourceFunc(baseURL string) func() simplestreams.DataSource {
return func() simplestreams.DataSource {
return simplestreams.NewURLSignedDataSource(
"ubuntu cloud images",
baseURL,
imagemetadata.SimplestreamsImagesPublicKey,
utils.VerifySSLHostnames,
simplestreams.DEFAULT_CLOUD_DATA,
true)
}
} | [
"func",
"newDataSourceFunc",
"(",
"baseURL",
"string",
")",
"func",
"(",
")",
"simplestreams",
".",
"DataSource",
"{",
"return",
"func",
"(",
")",
"simplestreams",
".",
"DataSource",
"{",
"return",
"simplestreams",
".",
"NewURLSignedDataSource",
"(",
"\"",
"\"",
",",
"baseURL",
",",
"imagemetadata",
".",
"SimplestreamsImagesPublicKey",
",",
"utils",
".",
"VerifySSLHostnames",
",",
"simplestreams",
".",
"DEFAULT_CLOUD_DATA",
",",
"true",
")",
"\n",
"}",
"\n",
"}"
] | // NewDataSource returns a datasourceFunc from the baseURL provided. | [
"NewDataSource",
"returns",
"a",
"datasourceFunc",
"from",
"the",
"baseURL",
"provided",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/imagedownloads/simplestreams.go#L43-L53 |
155,028 | juju/juju | environs/imagedownloads/simplestreams.go | DownloadURL | func (m *Metadata) DownloadURL() (*url.URL, error) {
if m.BaseURL == "" {
m.BaseURL = imagemetadata.UbuntuCloudImagesURL
}
u, err := url.Parse(m.BaseURL + "/" + m.Path)
if err != nil {
return nil, errors.Annotate(err, "failed to create url")
}
return u, nil
} | go | func (m *Metadata) DownloadURL() (*url.URL, error) {
if m.BaseURL == "" {
m.BaseURL = imagemetadata.UbuntuCloudImagesURL
}
u, err := url.Parse(m.BaseURL + "/" + m.Path)
if err != nil {
return nil, errors.Annotate(err, "failed to create url")
}
return u, nil
} | [
"func",
"(",
"m",
"*",
"Metadata",
")",
"DownloadURL",
"(",
")",
"(",
"*",
"url",
".",
"URL",
",",
"error",
")",
"{",
"if",
"m",
".",
"BaseURL",
"==",
"\"",
"\"",
"{",
"m",
".",
"BaseURL",
"=",
"imagemetadata",
".",
"UbuntuCloudImagesURL",
"\n",
"}",
"\n",
"u",
",",
"err",
":=",
"url",
".",
"Parse",
"(",
"m",
".",
"BaseURL",
"+",
"\"",
"\"",
"+",
"m",
".",
"Path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"u",
",",
"nil",
"\n",
"}"
] | // DownloadURL returns the URL representing the image. | [
"DownloadURL",
"returns",
"the",
"URL",
"representing",
"the",
"image",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/imagedownloads/simplestreams.go#L73-L82 |
155,029 | juju/juju | environs/imagedownloads/simplestreams.go | Fetch | func Fetch(
src []simplestreams.DataSource,
cons *imagemetadata.ImageConstraint,
ff simplestreams.AppendMatchingFunc) ([]*Metadata, *simplestreams.ResolveInfo, error) {
if ff == nil {
ff = Filter("")
}
params := simplestreams.GetMetadataParams{
StreamsVersion: imagemetadata.StreamsVersionV1,
LookupConstraint: cons,
ValueParams: simplestreams.ValueParams{
DataType: DataType,
FilterFunc: ff,
ValueTemplate: Metadata{},
},
}
items, resolveInfo, err := simplestreams.GetMetadata(src, params)
if err != nil {
return nil, resolveInfo, err
}
md := make([]*Metadata, len(items))
for i, im := range items {
md[i] = im.(*Metadata)
}
Sort(md)
return md, resolveInfo, nil
} | go | func Fetch(
src []simplestreams.DataSource,
cons *imagemetadata.ImageConstraint,
ff simplestreams.AppendMatchingFunc) ([]*Metadata, *simplestreams.ResolveInfo, error) {
if ff == nil {
ff = Filter("")
}
params := simplestreams.GetMetadataParams{
StreamsVersion: imagemetadata.StreamsVersionV1,
LookupConstraint: cons,
ValueParams: simplestreams.ValueParams{
DataType: DataType,
FilterFunc: ff,
ValueTemplate: Metadata{},
},
}
items, resolveInfo, err := simplestreams.GetMetadata(src, params)
if err != nil {
return nil, resolveInfo, err
}
md := make([]*Metadata, len(items))
for i, im := range items {
md[i] = im.(*Metadata)
}
Sort(md)
return md, resolveInfo, nil
} | [
"func",
"Fetch",
"(",
"src",
"[",
"]",
"simplestreams",
".",
"DataSource",
",",
"cons",
"*",
"imagemetadata",
".",
"ImageConstraint",
",",
"ff",
"simplestreams",
".",
"AppendMatchingFunc",
")",
"(",
"[",
"]",
"*",
"Metadata",
",",
"*",
"simplestreams",
".",
"ResolveInfo",
",",
"error",
")",
"{",
"if",
"ff",
"==",
"nil",
"{",
"ff",
"=",
"Filter",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"params",
":=",
"simplestreams",
".",
"GetMetadataParams",
"{",
"StreamsVersion",
":",
"imagemetadata",
".",
"StreamsVersionV1",
",",
"LookupConstraint",
":",
"cons",
",",
"ValueParams",
":",
"simplestreams",
".",
"ValueParams",
"{",
"DataType",
":",
"DataType",
",",
"FilterFunc",
":",
"ff",
",",
"ValueTemplate",
":",
"Metadata",
"{",
"}",
",",
"}",
",",
"}",
"\n",
"items",
",",
"resolveInfo",
",",
"err",
":=",
"simplestreams",
".",
"GetMetadata",
"(",
"src",
",",
"params",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"resolveInfo",
",",
"err",
"\n",
"}",
"\n",
"md",
":=",
"make",
"(",
"[",
"]",
"*",
"Metadata",
",",
"len",
"(",
"items",
")",
")",
"\n",
"for",
"i",
",",
"im",
":=",
"range",
"items",
"{",
"md",
"[",
"i",
"]",
"=",
"im",
".",
"(",
"*",
"Metadata",
")",
"\n",
"}",
"\n\n",
"Sort",
"(",
"md",
")",
"\n\n",
"return",
"md",
",",
"resolveInfo",
",",
"nil",
"\n",
"}"
] | // Fetch gets product results as Metadata from the provided datasources, given
// some constraints and an optional filter function. | [
"Fetch",
"gets",
"product",
"results",
"as",
"Metadata",
"from",
"the",
"provided",
"datasources",
"given",
"some",
"constraints",
"and",
"an",
"optional",
"filter",
"function",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/imagedownloads/simplestreams.go#L86-L114 |
155,030 | juju/juju | environs/imagedownloads/simplestreams.go | Filter | func Filter(ftype string) simplestreams.AppendMatchingFunc {
return func(source simplestreams.DataSource, matchingImages []interface{},
images map[string]interface{}, cons simplestreams.LookupConstraint) ([]interface{}, error) {
imagesMap := make(map[imageKey]*Metadata, len(matchingImages))
for _, val := range matchingImages {
im := val.(*Metadata)
imagesMap[imageKey{im.Arch, im.FType, im.Release, im.Version}] = im
}
for _, val := range images {
im := val.(*Metadata)
if ftype != "" {
if im.FType != ftype {
continue
}
}
if _, ok := imagesMap[imageKey{im.Arch, im.FType, im.Release, im.Version}]; !ok {
matchingImages = append(matchingImages, im)
}
}
return matchingImages, nil
}
} | go | func Filter(ftype string) simplestreams.AppendMatchingFunc {
return func(source simplestreams.DataSource, matchingImages []interface{},
images map[string]interface{}, cons simplestreams.LookupConstraint) ([]interface{}, error) {
imagesMap := make(map[imageKey]*Metadata, len(matchingImages))
for _, val := range matchingImages {
im := val.(*Metadata)
imagesMap[imageKey{im.Arch, im.FType, im.Release, im.Version}] = im
}
for _, val := range images {
im := val.(*Metadata)
if ftype != "" {
if im.FType != ftype {
continue
}
}
if _, ok := imagesMap[imageKey{im.Arch, im.FType, im.Release, im.Version}]; !ok {
matchingImages = append(matchingImages, im)
}
}
return matchingImages, nil
}
} | [
"func",
"Filter",
"(",
"ftype",
"string",
")",
"simplestreams",
".",
"AppendMatchingFunc",
"{",
"return",
"func",
"(",
"source",
"simplestreams",
".",
"DataSource",
",",
"matchingImages",
"[",
"]",
"interface",
"{",
"}",
",",
"images",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
",",
"cons",
"simplestreams",
".",
"LookupConstraint",
")",
"(",
"[",
"]",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"imagesMap",
":=",
"make",
"(",
"map",
"[",
"imageKey",
"]",
"*",
"Metadata",
",",
"len",
"(",
"matchingImages",
")",
")",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"matchingImages",
"{",
"im",
":=",
"val",
".",
"(",
"*",
"Metadata",
")",
"\n",
"imagesMap",
"[",
"imageKey",
"{",
"im",
".",
"Arch",
",",
"im",
".",
"FType",
",",
"im",
".",
"Release",
",",
"im",
".",
"Version",
"}",
"]",
"=",
"im",
"\n",
"}",
"\n",
"for",
"_",
",",
"val",
":=",
"range",
"images",
"{",
"im",
":=",
"val",
".",
"(",
"*",
"Metadata",
")",
"\n",
"if",
"ftype",
"!=",
"\"",
"\"",
"{",
"if",
"im",
".",
"FType",
"!=",
"ftype",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"imagesMap",
"[",
"imageKey",
"{",
"im",
".",
"Arch",
",",
"im",
".",
"FType",
",",
"im",
".",
"Release",
",",
"im",
".",
"Version",
"}",
"]",
";",
"!",
"ok",
"{",
"matchingImages",
"=",
"append",
"(",
"matchingImages",
",",
"im",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"matchingImages",
",",
"nil",
"\n",
"}",
"\n",
"}"
] | // Filter collects only matching products. Series and Arch are filtered by
// imagemetadata.ImageConstraints. So this really only let's us filter on a
// file type. | [
"Filter",
"collects",
"only",
"matching",
"products",
".",
"Series",
"and",
"Arch",
"are",
"filtered",
"by",
"imagemetadata",
".",
"ImageConstraints",
".",
"So",
"this",
"really",
"only",
"let",
"s",
"us",
"filter",
"on",
"a",
"file",
"type",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/environs/imagedownloads/simplestreams.go#L213-L235 |
155,031 | juju/juju | cmd/juju/cloud/list.go | NewListCloudsCommand | func NewListCloudsCommand() cmd.Command {
store := jujuclient.NewFileClientStore()
c := &listCloudsCommand{
OptionalControllerCommand: modelcmd.OptionalControllerCommand{Store: store},
store: store,
}
c.listCloudsAPIFunc = c.cloudAPI
return modelcmd.WrapBase(c)
} | go | func NewListCloudsCommand() cmd.Command {
store := jujuclient.NewFileClientStore()
c := &listCloudsCommand{
OptionalControllerCommand: modelcmd.OptionalControllerCommand{Store: store},
store: store,
}
c.listCloudsAPIFunc = c.cloudAPI
return modelcmd.WrapBase(c)
} | [
"func",
"NewListCloudsCommand",
"(",
")",
"cmd",
".",
"Command",
"{",
"store",
":=",
"jujuclient",
".",
"NewFileClientStore",
"(",
")",
"\n",
"c",
":=",
"&",
"listCloudsCommand",
"{",
"OptionalControllerCommand",
":",
"modelcmd",
".",
"OptionalControllerCommand",
"{",
"Store",
":",
"store",
"}",
",",
"store",
":",
"store",
",",
"}",
"\n",
"c",
".",
"listCloudsAPIFunc",
"=",
"c",
".",
"cloudAPI",
"\n\n",
"return",
"modelcmd",
".",
"WrapBase",
"(",
"c",
")",
"\n",
"}"
] | // NewListCloudsCommand returns a command to list cloud information. | [
"NewListCloudsCommand",
"returns",
"a",
"command",
"to",
"list",
"cloud",
"information",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/cloud/list.go#L80-L89 |
155,032 | juju/juju | cmd/juju/cloud/list.go | formatCloudsTabular | func formatCloudsTabular(writer io.Writer, value interface{}) error {
clouds, ok := value.(*cloudList)
if !ok {
return errors.Errorf("expected value of type %T, got %T", clouds, value)
}
tw := output.TabWriter(writer)
w := output.Wrapper{tw}
w.Println("Cloud", "Regions", "Default", "Type", "Description")
w.SetColumnAlignRight(1)
cloudNamesSorted := func(someClouds map[string]*CloudDetails) []string {
// For tabular we'll sort alphabetically, user clouds last.
var names []string
for name := range someClouds {
names = append(names, name)
}
sort.Strings(names)
return names
}
printClouds := func(someClouds map[string]*CloudDetails, color *ansiterm.Context) {
cloudNames := cloudNamesSorted(someClouds)
for _, name := range cloudNames {
info := someClouds[name]
defaultRegion := ""
if len(info.Regions) > 0 {
defaultRegion = info.RegionsMap[info.Regions[0].Key.(string)].Name
}
description := info.CloudDescription
if len(description) > 40 {
description = description[:39]
}
w.PrintColor(color, name)
w.Println(len(info.Regions), defaultRegion, displayCloudType(info.CloudType), description)
}
}
printClouds(clouds.public, nil)
printClouds(clouds.builtin, nil)
printClouds(clouds.personal, ansiterm.Foreground(ansiterm.BrightBlue))
tw.Flush()
return nil
} | go | func formatCloudsTabular(writer io.Writer, value interface{}) error {
clouds, ok := value.(*cloudList)
if !ok {
return errors.Errorf("expected value of type %T, got %T", clouds, value)
}
tw := output.TabWriter(writer)
w := output.Wrapper{tw}
w.Println("Cloud", "Regions", "Default", "Type", "Description")
w.SetColumnAlignRight(1)
cloudNamesSorted := func(someClouds map[string]*CloudDetails) []string {
// For tabular we'll sort alphabetically, user clouds last.
var names []string
for name := range someClouds {
names = append(names, name)
}
sort.Strings(names)
return names
}
printClouds := func(someClouds map[string]*CloudDetails, color *ansiterm.Context) {
cloudNames := cloudNamesSorted(someClouds)
for _, name := range cloudNames {
info := someClouds[name]
defaultRegion := ""
if len(info.Regions) > 0 {
defaultRegion = info.RegionsMap[info.Regions[0].Key.(string)].Name
}
description := info.CloudDescription
if len(description) > 40 {
description = description[:39]
}
w.PrintColor(color, name)
w.Println(len(info.Regions), defaultRegion, displayCloudType(info.CloudType), description)
}
}
printClouds(clouds.public, nil)
printClouds(clouds.builtin, nil)
printClouds(clouds.personal, ansiterm.Foreground(ansiterm.BrightBlue))
tw.Flush()
return nil
} | [
"func",
"formatCloudsTabular",
"(",
"writer",
"io",
".",
"Writer",
",",
"value",
"interface",
"{",
"}",
")",
"error",
"{",
"clouds",
",",
"ok",
":=",
"value",
".",
"(",
"*",
"cloudList",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"clouds",
",",
"value",
")",
"\n",
"}",
"\n\n",
"tw",
":=",
"output",
".",
"TabWriter",
"(",
"writer",
")",
"\n",
"w",
":=",
"output",
".",
"Wrapper",
"{",
"tw",
"}",
"\n",
"w",
".",
"Println",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"w",
".",
"SetColumnAlignRight",
"(",
"1",
")",
"\n\n",
"cloudNamesSorted",
":=",
"func",
"(",
"someClouds",
"map",
"[",
"string",
"]",
"*",
"CloudDetails",
")",
"[",
"]",
"string",
"{",
"// For tabular we'll sort alphabetically, user clouds last.",
"var",
"names",
"[",
"]",
"string",
"\n",
"for",
"name",
":=",
"range",
"someClouds",
"{",
"names",
"=",
"append",
"(",
"names",
",",
"name",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"names",
")",
"\n",
"return",
"names",
"\n",
"}",
"\n\n",
"printClouds",
":=",
"func",
"(",
"someClouds",
"map",
"[",
"string",
"]",
"*",
"CloudDetails",
",",
"color",
"*",
"ansiterm",
".",
"Context",
")",
"{",
"cloudNames",
":=",
"cloudNamesSorted",
"(",
"someClouds",
")",
"\n\n",
"for",
"_",
",",
"name",
":=",
"range",
"cloudNames",
"{",
"info",
":=",
"someClouds",
"[",
"name",
"]",
"\n",
"defaultRegion",
":=",
"\"",
"\"",
"\n",
"if",
"len",
"(",
"info",
".",
"Regions",
")",
">",
"0",
"{",
"defaultRegion",
"=",
"info",
".",
"RegionsMap",
"[",
"info",
".",
"Regions",
"[",
"0",
"]",
".",
"Key",
".",
"(",
"string",
")",
"]",
".",
"Name",
"\n",
"}",
"\n",
"description",
":=",
"info",
".",
"CloudDescription",
"\n",
"if",
"len",
"(",
"description",
")",
">",
"40",
"{",
"description",
"=",
"description",
"[",
":",
"39",
"]",
"\n",
"}",
"\n",
"w",
".",
"PrintColor",
"(",
"color",
",",
"name",
")",
"\n",
"w",
".",
"Println",
"(",
"len",
"(",
"info",
".",
"Regions",
")",
",",
"defaultRegion",
",",
"displayCloudType",
"(",
"info",
".",
"CloudType",
")",
",",
"description",
")",
"\n",
"}",
"\n",
"}",
"\n",
"printClouds",
"(",
"clouds",
".",
"public",
",",
"nil",
")",
"\n",
"printClouds",
"(",
"clouds",
".",
"builtin",
",",
"nil",
")",
"\n",
"printClouds",
"(",
"clouds",
".",
"personal",
",",
"ansiterm",
".",
"Foreground",
"(",
"ansiterm",
".",
"BrightBlue",
")",
")",
"\n\n",
"tw",
".",
"Flush",
"(",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // formatCloudsTabular writes a tabular summary of cloud information. | [
"formatCloudsTabular",
"writes",
"a",
"tabular",
"summary",
"of",
"cloud",
"information",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/cloud/list.go#L256-L300 |
155,033 | juju/juju | payload/payload.go | Validate | func (p Payload) Validate() error {
if err := p.PayloadClass.Validate(); err != nil {
return errors.NewNotValid(err, "")
}
if p.ID == "" {
return errors.NotValidf("missing ID")
}
if err := ValidateState(p.Status); err != nil {
return errors.Trace(err)
}
// TODO(ericsnow) Do not require Unit to be set?
if p.Unit == "" {
return errors.NotValidf("missing Unit")
}
return nil
} | go | func (p Payload) Validate() error {
if err := p.PayloadClass.Validate(); err != nil {
return errors.NewNotValid(err, "")
}
if p.ID == "" {
return errors.NotValidf("missing ID")
}
if err := ValidateState(p.Status); err != nil {
return errors.Trace(err)
}
// TODO(ericsnow) Do not require Unit to be set?
if p.Unit == "" {
return errors.NotValidf("missing Unit")
}
return nil
} | [
"func",
"(",
"p",
"Payload",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"p",
".",
"PayloadClass",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"NewNotValid",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"p",
".",
"ID",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"ValidateState",
"(",
"p",
".",
"Status",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"// TODO(ericsnow) Do not require Unit to be set?",
"if",
"p",
".",
"Unit",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotValidf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate checks the payload info to ensure it is correct. | [
"Validate",
"checks",
"the",
"payload",
"info",
"to",
"ensure",
"it",
"is",
"correct",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/payload/payload.go#L37-L56 |
155,034 | juju/juju | service/upstart/upstart.go | IsRunning | func IsRunning() (bool, error) {
// On windows casting the error to exec.Error does not yield a os.PathError type
// It's easyer to just return false before even trying to execute an external command
// on windows at least
if runtime.GOOS == "windows" {
return false, nil
}
// TODO(ericsnow) This function should be fixed to precisely match
// the equivalent shell script line in service/discovery.go.
cmd := exec.Command(initctlPath, "--system", "list")
_, err := cmd.CombinedOutput()
if err == nil {
return true, nil
}
if common.IsCmdNotFoundErr(err) {
return false, nil
}
// Note: initctl will fail if upstart is installed but not running.
// The error message will be:
// Name "com.ubuntu.Upstart" does not exist
return false, errors.Annotatef(err, "exec %q failed", initctlPath)
} | go | func IsRunning() (bool, error) {
// On windows casting the error to exec.Error does not yield a os.PathError type
// It's easyer to just return false before even trying to execute an external command
// on windows at least
if runtime.GOOS == "windows" {
return false, nil
}
// TODO(ericsnow) This function should be fixed to precisely match
// the equivalent shell script line in service/discovery.go.
cmd := exec.Command(initctlPath, "--system", "list")
_, err := cmd.CombinedOutput()
if err == nil {
return true, nil
}
if common.IsCmdNotFoundErr(err) {
return false, nil
}
// Note: initctl will fail if upstart is installed but not running.
// The error message will be:
// Name "com.ubuntu.Upstart" does not exist
return false, errors.Annotatef(err, "exec %q failed", initctlPath)
} | [
"func",
"IsRunning",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// On windows casting the error to exec.Error does not yield a os.PathError type",
"// It's easyer to just return false before even trying to execute an external command",
"// on windows at least",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"// TODO(ericsnow) This function should be fixed to precisely match",
"// the equivalent shell script line in service/discovery.go.",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"initctlPath",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"_",
",",
"err",
":=",
"cmd",
".",
"CombinedOutput",
"(",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n\n",
"if",
"common",
".",
"IsCmdNotFoundErr",
"(",
"err",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"// Note: initctl will fail if upstart is installed but not running.",
"// The error message will be:",
"// Name \"com.ubuntu.Upstart\" does not exist",
"return",
"false",
",",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
",",
"initctlPath",
")",
"\n",
"}"
] | // IsRunning returns whether or not upstart is the local init system. | [
"IsRunning",
"returns",
"whether",
"or",
"not",
"upstart",
"is",
"the",
"local",
"init",
"system",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/upstart/upstart.go#L34-L58 |
155,035 | juju/juju | service/upstart/upstart.go | ListServices | func ListServices() ([]string, error) {
fis, err := ioutil.ReadDir(InitDir)
if err != nil {
return nil, errors.Trace(err)
}
var services []string
for _, fi := range fis {
if groups := servicesRe.FindStringSubmatch(fi.Name()); len(groups) > 0 {
services = append(services, groups[1])
}
}
return services, nil
} | go | func ListServices() ([]string, error) {
fis, err := ioutil.ReadDir(InitDir)
if err != nil {
return nil, errors.Trace(err)
}
var services []string
for _, fi := range fis {
if groups := servicesRe.FindStringSubmatch(fi.Name()); len(groups) > 0 {
services = append(services, groups[1])
}
}
return services, nil
} | [
"func",
"ListServices",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"fis",
",",
"err",
":=",
"ioutil",
".",
"ReadDir",
"(",
"InitDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"services",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"fi",
":=",
"range",
"fis",
"{",
"if",
"groups",
":=",
"servicesRe",
".",
"FindStringSubmatch",
"(",
"fi",
".",
"Name",
"(",
")",
")",
";",
"len",
"(",
"groups",
")",
">",
"0",
"{",
"services",
"=",
"append",
"(",
"services",
",",
"groups",
"[",
"1",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"services",
",",
"nil",
"\n",
"}"
] | // ListServices returns the name of all installed services on the
// local host. | [
"ListServices",
"returns",
"the",
"name",
"of",
"all",
"installed",
"services",
"on",
"the",
"local",
"host",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/upstart/upstart.go#L62-L75 |
155,036 | juju/juju | service/upstart/upstart.go | confPath | func (s *Service) confPath() string {
return path.Join(InitDir, s.Service.Name+".conf")
} | go | func (s *Service) confPath() string {
return path.Join(InitDir, s.Service.Name+".conf")
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"confPath",
"(",
")",
"string",
"{",
"return",
"path",
".",
"Join",
"(",
"InitDir",
",",
"s",
".",
"Service",
".",
"Name",
"+",
"\"",
"\"",
")",
"\n",
"}"
] | // confPath returns the path to the service's configuration file. | [
"confPath",
"returns",
"the",
"path",
"to",
"the",
"service",
"s",
"configuration",
"file",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/upstart/upstart.go#L110-L112 |
155,037 | juju/juju | service/upstart/upstart.go | Validate | func (s *Service) Validate() error {
if err := s.Service.Validate(renderer); err != nil {
return errors.Trace(err)
}
if s.Service.Conf.Transient {
if len(s.Service.Conf.Env) > 0 {
return errors.NotSupportedf("Conf.Env (when transient)")
}
if len(s.Service.Conf.Limit) > 0 {
return errors.NotSupportedf("Conf.Limit (when transient)")
}
if s.Service.Conf.Logfile != "" {
return errors.NotSupportedf("Conf.Logfile (when transient)")
}
if s.Service.Conf.ExtraScript != "" {
return errors.NotSupportedf("Conf.ExtraScript (when transient)")
}
} else {
if s.Service.Conf.AfterStopped != "" {
return errors.NotSupportedf("Conf.AfterStopped (when not transient)")
}
if s.Service.Conf.ExecStopPost != "" {
return errors.NotSupportedf("Conf.ExecStopPost (when not transient)")
}
}
return nil
} | go | func (s *Service) Validate() error {
if err := s.Service.Validate(renderer); err != nil {
return errors.Trace(err)
}
if s.Service.Conf.Transient {
if len(s.Service.Conf.Env) > 0 {
return errors.NotSupportedf("Conf.Env (when transient)")
}
if len(s.Service.Conf.Limit) > 0 {
return errors.NotSupportedf("Conf.Limit (when transient)")
}
if s.Service.Conf.Logfile != "" {
return errors.NotSupportedf("Conf.Logfile (when transient)")
}
if s.Service.Conf.ExtraScript != "" {
return errors.NotSupportedf("Conf.ExtraScript (when transient)")
}
} else {
if s.Service.Conf.AfterStopped != "" {
return errors.NotSupportedf("Conf.AfterStopped (when not transient)")
}
if s.Service.Conf.ExecStopPost != "" {
return errors.NotSupportedf("Conf.ExecStopPost (when not transient)")
}
}
return nil
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"s",
".",
"Service",
".",
"Validate",
"(",
"renderer",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"s",
".",
"Service",
".",
"Conf",
".",
"Transient",
"{",
"if",
"len",
"(",
"s",
".",
"Service",
".",
"Conf",
".",
"Env",
")",
">",
"0",
"{",
"return",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"s",
".",
"Service",
".",
"Conf",
".",
"Limit",
")",
">",
"0",
"{",
"return",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"Service",
".",
"Conf",
".",
"Logfile",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"Service",
".",
"Conf",
".",
"ExtraScript",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"s",
".",
"Service",
".",
"Conf",
".",
"AfterStopped",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"s",
".",
"Service",
".",
"Conf",
".",
"ExecStopPost",
"!=",
"\"",
"\"",
"{",
"return",
"errors",
".",
"NotSupportedf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Validate returns an error if the service is not adequately defined. | [
"Validate",
"returns",
"an",
"error",
"if",
"the",
"service",
"is",
"not",
"adequately",
"defined",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/upstart/upstart.go#L115-L143 |
155,038 | juju/juju | service/upstart/upstart.go | render | func (s *Service) render() ([]byte, error) {
if err := s.Validate(); err != nil {
return nil, err
}
conf := s.Conf()
if conf.Transient {
conf.ExecStopPost = "rm " + s.confPath()
}
return Serialize(s.Name(), conf)
} | go | func (s *Service) render() ([]byte, error) {
if err := s.Validate(); err != nil {
return nil, err
}
conf := s.Conf()
if conf.Transient {
conf.ExecStopPost = "rm " + s.confPath()
}
return Serialize(s.Name(), conf)
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"render",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"err",
":=",
"s",
".",
"Validate",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"conf",
":=",
"s",
".",
"Conf",
"(",
")",
"\n",
"if",
"conf",
".",
"Transient",
"{",
"conf",
".",
"ExecStopPost",
"=",
"\"",
"\"",
"+",
"s",
".",
"confPath",
"(",
")",
"\n",
"}",
"\n",
"return",
"Serialize",
"(",
"s",
".",
"Name",
"(",
")",
",",
"conf",
")",
"\n",
"}"
] | // render returns the upstart configuration for the application as a slice of bytes. | [
"render",
"returns",
"the",
"upstart",
"configuration",
"for",
"the",
"application",
"as",
"a",
"slice",
"of",
"bytes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/upstart/upstart.go#L146-L155 |
155,039 | juju/juju | service/upstart/upstart.go | Installed | func (s *Service) Installed() (bool, error) {
_, err := os.Stat(s.confPath())
if os.IsNotExist(err) {
return false, nil
}
if err != nil {
return false, errors.Trace(err)
}
return true, nil
} | go | func (s *Service) Installed() (bool, error) {
_, err := os.Stat(s.confPath())
if os.IsNotExist(err) {
return false, nil
}
if err != nil {
return false, errors.Trace(err)
}
return true, nil
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Installed",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"s",
".",
"confPath",
"(",
")",
")",
"\n",
"if",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}"
] | // Installed returns whether the service configuration exists in the
// init directory. | [
"Installed",
"returns",
"whether",
"the",
"service",
"configuration",
"exists",
"in",
"the",
"init",
"directory",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/upstart/upstart.go#L159-L168 |
155,040 | juju/juju | service/upstart/upstart.go | Exists | func (s *Service) Exists() (bool, error) {
// In any error case, we just say it doesn't exist with this configuration.
// Subsequent calls into the Service will give the caller more useful errors.
_, same, _, err := s.existsAndSame()
if err != nil {
return false, errors.Trace(err)
}
return same, nil
} | go | func (s *Service) Exists() (bool, error) {
// In any error case, we just say it doesn't exist with this configuration.
// Subsequent calls into the Service will give the caller more useful errors.
_, same, _, err := s.existsAndSame()
if err != nil {
return false, errors.Trace(err)
}
return same, nil
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Exists",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// In any error case, we just say it doesn't exist with this configuration.",
"// Subsequent calls into the Service will give the caller more useful errors.",
"_",
",",
"same",
",",
"_",
",",
"err",
":=",
"s",
".",
"existsAndSame",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"same",
",",
"nil",
"\n",
"}"
] | // Exists returns whether the service configuration exists in the
// init directory with the same content that this Service would have
// if installed. | [
"Exists",
"returns",
"whether",
"the",
"service",
"configuration",
"exists",
"in",
"the",
"init",
"directory",
"with",
"the",
"same",
"content",
"that",
"this",
"Service",
"would",
"have",
"if",
"installed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/upstart/upstart.go#L173-L181 |
155,041 | juju/juju | service/upstart/upstart.go | Running | func (s *Service) Running() (bool, error) {
cmd := exec.Command("status", "--system", s.Service.Name)
out, err := cmd.CombinedOutput()
logger.Tracef("Running \"status --system %s\": %q", s.Service.Name, out)
if err == nil {
return startedRE.Match(out), nil
}
if err.Error() != "exit status 1" {
return false, errors.Trace(err)
}
return false, nil
} | go | func (s *Service) Running() (bool, error) {
cmd := exec.Command("status", "--system", s.Service.Name)
out, err := cmd.CombinedOutput()
logger.Tracef("Running \"status --system %s\": %q", s.Service.Name, out)
if err == nil {
return startedRE.Match(out), nil
}
if err.Error() != "exit status 1" {
return false, errors.Trace(err)
}
return false, nil
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Running",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"cmd",
":=",
"exec",
".",
"Command",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"s",
".",
"Service",
".",
"Name",
")",
"\n",
"out",
",",
"err",
":=",
"cmd",
".",
"CombinedOutput",
"(",
")",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"s",
".",
"Service",
".",
"Name",
",",
"out",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"startedRE",
".",
"Match",
"(",
"out",
")",
",",
"nil",
"\n",
"}",
"\n",
"if",
"err",
".",
"Error",
"(",
")",
"!=",
"\"",
"\"",
"{",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"false",
",",
"nil",
"\n",
"}"
] | // Running returns true if the Service appears to be running. | [
"Running",
"returns",
"true",
"if",
"the",
"Service",
"appears",
"to",
"be",
"running",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/upstart/upstart.go#L200-L211 |
155,042 | juju/juju | service/upstart/upstart.go | Remove | func (s *Service) Remove() error {
installed, err := s.Installed()
if err != nil {
return errors.Trace(err)
}
if !installed {
return nil
}
return os.Remove(s.confPath())
} | go | func (s *Service) Remove() error {
installed, err := s.Installed()
if err != nil {
return errors.Trace(err)
}
if !installed {
return nil
}
return os.Remove(s.confPath())
} | [
"func",
"(",
"s",
"*",
"Service",
")",
"Remove",
"(",
")",
"error",
"{",
"installed",
",",
"err",
":=",
"s",
".",
"Installed",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"installed",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"os",
".",
"Remove",
"(",
"s",
".",
"confPath",
"(",
")",
")",
"\n",
"}"
] | // Remove deletes the service configuration from the init directory. | [
"Remove",
"deletes",
"the",
"service",
"configuration",
"from",
"the",
"init",
"directory",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/upstart/upstart.go#L263-L272 |
155,043 | juju/juju | service/upstart/upstart.go | Serialize | func Serialize(name string, conf common.Conf) ([]byte, error) {
var buf bytes.Buffer
if conf.Transient {
if err := transientConfT.Execute(&buf, conf); err != nil {
return nil, err
}
} else {
if err := confT.Execute(&buf, conf); err != nil {
return nil, err
}
}
return buf.Bytes(), nil
} | go | func Serialize(name string, conf common.Conf) ([]byte, error) {
var buf bytes.Buffer
if conf.Transient {
if err := transientConfT.Execute(&buf, conf); err != nil {
return nil, err
}
} else {
if err := confT.Execute(&buf, conf); err != nil {
return nil, err
}
}
return buf.Bytes(), nil
} | [
"func",
"Serialize",
"(",
"name",
"string",
",",
"conf",
"common",
".",
"Conf",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"buf",
"bytes",
".",
"Buffer",
"\n",
"if",
"conf",
".",
"Transient",
"{",
"if",
"err",
":=",
"transientConfT",
".",
"Execute",
"(",
"&",
"buf",
",",
"conf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"if",
"err",
":=",
"confT",
".",
"Execute",
"(",
"&",
"buf",
",",
"conf",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"buf",
".",
"Bytes",
"(",
")",
",",
"nil",
"\n",
"}"
] | // Serialize renders the conf as raw bytes. | [
"Serialize",
"renders",
"the",
"conf",
"as",
"raw",
"bytes",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/service/upstart/upstart.go#L318-L330 |
155,044 | juju/juju | cmd/juju/storage/attach.go | NewAttachStorageCommandWithAPI | func NewAttachStorageCommandWithAPI() cmd.Command {
cmd := &attachStorageCommand{}
cmd.newEntityAttacherCloser = func() (EntityAttacherCloser, error) {
return cmd.NewStorageAPI()
}
return modelcmd.Wrap(cmd)
} | go | func NewAttachStorageCommandWithAPI() cmd.Command {
cmd := &attachStorageCommand{}
cmd.newEntityAttacherCloser = func() (EntityAttacherCloser, error) {
return cmd.NewStorageAPI()
}
return modelcmd.Wrap(cmd)
} | [
"func",
"NewAttachStorageCommandWithAPI",
"(",
")",
"cmd",
".",
"Command",
"{",
"cmd",
":=",
"&",
"attachStorageCommand",
"{",
"}",
"\n",
"cmd",
".",
"newEntityAttacherCloser",
"=",
"func",
"(",
")",
"(",
"EntityAttacherCloser",
",",
"error",
")",
"{",
"return",
"cmd",
".",
"NewStorageAPI",
"(",
")",
"\n",
"}",
"\n",
"return",
"modelcmd",
".",
"Wrap",
"(",
"cmd",
")",
"\n",
"}"
] | // NewAttachStorageCommandWithAPI returns a command
// used to attach storage to application units. | [
"NewAttachStorageCommandWithAPI",
"returns",
"a",
"command",
"used",
"to",
"attach",
"storage",
"to",
"application",
"units",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/attach.go#L18-L24 |
155,045 | juju/juju | cmd/juju/storage/attach.go | NewAttachStorageCommand | func NewAttachStorageCommand(new NewEntityAttacherCloserFunc) cmd.Command {
cmd := &attachStorageCommand{}
cmd.newEntityAttacherCloser = new
return modelcmd.Wrap(cmd)
} | go | func NewAttachStorageCommand(new NewEntityAttacherCloserFunc) cmd.Command {
cmd := &attachStorageCommand{}
cmd.newEntityAttacherCloser = new
return modelcmd.Wrap(cmd)
} | [
"func",
"NewAttachStorageCommand",
"(",
"new",
"NewEntityAttacherCloserFunc",
")",
"cmd",
".",
"Command",
"{",
"cmd",
":=",
"&",
"attachStorageCommand",
"{",
"}",
"\n",
"cmd",
".",
"newEntityAttacherCloser",
"=",
"new",
"\n",
"return",
"modelcmd",
".",
"Wrap",
"(",
"cmd",
")",
"\n",
"}"
] | // NewAttachStorageCommand returns a command used to
// attach storage to application units. | [
"NewAttachStorageCommand",
"returns",
"a",
"command",
"used",
"to",
"attach",
"storage",
"to",
"application",
"units",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/storage/attach.go#L28-L32 |
155,046 | juju/juju | apiserver/facades/agent/migrationminion/migrationminion.go | Report | func (api *API) Report(info params.MinionReport) error {
phase, ok := migration.ParsePhase(info.Phase)
if !ok {
return errors.New("unable to parse phase")
}
mig, err := api.backend.Migration(info.MigrationId)
if err != nil {
return errors.Trace(err)
}
err = mig.SubmitMinionReport(api.authorizer.GetAuthTag(), phase, info.Success)
return errors.Trace(err)
} | go | func (api *API) Report(info params.MinionReport) error {
phase, ok := migration.ParsePhase(info.Phase)
if !ok {
return errors.New("unable to parse phase")
}
mig, err := api.backend.Migration(info.MigrationId)
if err != nil {
return errors.Trace(err)
}
err = mig.SubmitMinionReport(api.authorizer.GetAuthTag(), phase, info.Success)
return errors.Trace(err)
} | [
"func",
"(",
"api",
"*",
"API",
")",
"Report",
"(",
"info",
"params",
".",
"MinionReport",
")",
"error",
"{",
"phase",
",",
"ok",
":=",
"migration",
".",
"ParsePhase",
"(",
"info",
".",
"Phase",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"mig",
",",
"err",
":=",
"api",
".",
"backend",
".",
"Migration",
"(",
"info",
".",
"MigrationId",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"err",
"=",
"mig",
".",
"SubmitMinionReport",
"(",
"api",
".",
"authorizer",
".",
"GetAuthTag",
"(",
")",
",",
"phase",
",",
"info",
".",
"Success",
")",
"\n",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}"
] | // Report allows a migration minion to submit whether it succeeded or
// failed for a specific migration phase. | [
"Report",
"allows",
"a",
"migration",
"minion",
"to",
"submit",
"whether",
"it",
"succeeded",
"or",
"failed",
"for",
"a",
"specific",
"migration",
"phase",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/migrationminion/migrationminion.go#L56-L69 |
155,047 | juju/juju | api/logger/logger.go | LoggingConfig | func (st *State) LoggingConfig(agentTag names.Tag) (string, error) {
var results params.StringResults
args := params.Entities{
Entities: []params.Entity{{Tag: agentTag.String()}},
}
err := st.facade.FacadeCall("LoggingConfig", args, &results)
if err != nil {
// TODO: Not directly tested
return "", err
}
if len(results.Results) != 1 {
// TODO: Not directly tested
return "", fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if err := result.Error; err != nil {
return "", err
}
return result.Result, nil
} | go | func (st *State) LoggingConfig(agentTag names.Tag) (string, error) {
var results params.StringResults
args := params.Entities{
Entities: []params.Entity{{Tag: agentTag.String()}},
}
err := st.facade.FacadeCall("LoggingConfig", args, &results)
if err != nil {
// TODO: Not directly tested
return "", err
}
if len(results.Results) != 1 {
// TODO: Not directly tested
return "", fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if err := result.Error; err != nil {
return "", err
}
return result.Result, nil
} | [
"func",
"(",
"st",
"*",
"State",
")",
"LoggingConfig",
"(",
"agentTag",
"names",
".",
"Tag",
")",
"(",
"string",
",",
"error",
")",
"{",
"var",
"results",
"params",
".",
"StringResults",
"\n",
"args",
":=",
"params",
".",
"Entities",
"{",
"Entities",
":",
"[",
"]",
"params",
".",
"Entity",
"{",
"{",
"Tag",
":",
"agentTag",
".",
"String",
"(",
")",
"}",
"}",
",",
"}",
"\n",
"err",
":=",
"st",
".",
"facade",
".",
"FacadeCall",
"(",
"\"",
"\"",
",",
"args",
",",
"&",
"results",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// TODO: Not directly tested",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"results",
".",
"Results",
")",
"!=",
"1",
"{",
"// TODO: Not directly tested",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"len",
"(",
"results",
".",
"Results",
")",
")",
"\n",
"}",
"\n",
"result",
":=",
"results",
".",
"Results",
"[",
"0",
"]",
"\n",
"if",
"err",
":=",
"result",
".",
"Error",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"result",
".",
"Result",
",",
"nil",
"\n",
"}"
] | // LoggingConfig returns the loggo configuration string for the agent
// specified by agentTag. | [
"LoggingConfig",
"returns",
"the",
"loggo",
"configuration",
"string",
"for",
"the",
"agent",
"specified",
"by",
"agentTag",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/logger/logger.go#L30-L49 |
155,048 | juju/juju | state/devices.go | NewDeviceBackend | func NewDeviceBackend(st *State) (*deviceBackend, error) {
m, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
return &deviceBackend{
mb: st,
settings: NewStateSettings(st),
modelType: m.Type(),
config: m.ModelConfig,
application: st.Application,
unit: st.Unit,
machine: st.Machine,
}, nil
} | go | func NewDeviceBackend(st *State) (*deviceBackend, error) {
m, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
return &deviceBackend{
mb: st,
settings: NewStateSettings(st),
modelType: m.Type(),
config: m.ModelConfig,
application: st.Application,
unit: st.Unit,
machine: st.Machine,
}, nil
} | [
"func",
"NewDeviceBackend",
"(",
"st",
"*",
"State",
")",
"(",
"*",
"deviceBackend",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"&",
"deviceBackend",
"{",
"mb",
":",
"st",
",",
"settings",
":",
"NewStateSettings",
"(",
"st",
")",
",",
"modelType",
":",
"m",
".",
"Type",
"(",
")",
",",
"config",
":",
"m",
".",
"ModelConfig",
",",
"application",
":",
"st",
".",
"Application",
",",
"unit",
":",
"st",
".",
"Unit",
",",
"machine",
":",
"st",
".",
"Machine",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewDeviceBackend creates a backend for managing device. | [
"NewDeviceBackend",
"creates",
"a",
"backend",
"for",
"managing",
"device",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/devices.go#L36-L50 |
155,049 | juju/juju | state/devices.go | DeviceConstraints | func (db *deviceBackend) DeviceConstraints(id string) (map[string]DeviceConstraints, error) {
devices, err := readDeviceConstraints(db.mb, id)
if err == nil {
return devices, nil
} else if errors.IsNotFound(err) {
return map[string]DeviceConstraints{}, nil
}
return nil, err
} | go | func (db *deviceBackend) DeviceConstraints(id string) (map[string]DeviceConstraints, error) {
devices, err := readDeviceConstraints(db.mb, id)
if err == nil {
return devices, nil
} else if errors.IsNotFound(err) {
return map[string]DeviceConstraints{}, nil
}
return nil, err
} | [
"func",
"(",
"db",
"*",
"deviceBackend",
")",
"DeviceConstraints",
"(",
"id",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"DeviceConstraints",
",",
"error",
")",
"{",
"devices",
",",
"err",
":=",
"readDeviceConstraints",
"(",
"db",
".",
"mb",
",",
"id",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"devices",
",",
"nil",
"\n",
"}",
"else",
"if",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"map",
"[",
"string",
"]",
"DeviceConstraints",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}"
] | // DeviceConstraints returns the device constraints for the specified application. | [
"DeviceConstraints",
"returns",
"the",
"device",
"constraints",
"for",
"the",
"specified",
"application",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/devices.go#L89-L97 |
155,050 | juju/juju | cmd/modelcmd/controller.go | DetermineCurrentController | func DetermineCurrentController(store jujuclient.ClientStore) (string, error) {
modelController, _ := SplitModelName(os.Getenv(osenv.JujuModelEnvKey))
envController := os.Getenv(osenv.JujuControllerEnvKey)
if modelController != "" && envController != "" && modelController != envController {
return "", errors.Errorf("controller name from %v (%v) conflicts with value in %v (%v)",
osenv.JujuModelEnvKey, modelController,
osenv.JujuControllerEnvKey, envController,
)
}
controllerName := modelController
if controllerName == "" {
controllerName = envController
}
if controllerName == "" {
var err error
controllerName, err = store.CurrentController()
if err != nil {
return "", errors.Trace(err)
}
}
if _, err := store.ControllerByName(controllerName); err != nil {
return "", errors.Trace(err)
}
return controllerName, nil
} | go | func DetermineCurrentController(store jujuclient.ClientStore) (string, error) {
modelController, _ := SplitModelName(os.Getenv(osenv.JujuModelEnvKey))
envController := os.Getenv(osenv.JujuControllerEnvKey)
if modelController != "" && envController != "" && modelController != envController {
return "", errors.Errorf("controller name from %v (%v) conflicts with value in %v (%v)",
osenv.JujuModelEnvKey, modelController,
osenv.JujuControllerEnvKey, envController,
)
}
controllerName := modelController
if controllerName == "" {
controllerName = envController
}
if controllerName == "" {
var err error
controllerName, err = store.CurrentController()
if err != nil {
return "", errors.Trace(err)
}
}
if _, err := store.ControllerByName(controllerName); err != nil {
return "", errors.Trace(err)
}
return controllerName, nil
} | [
"func",
"DetermineCurrentController",
"(",
"store",
"jujuclient",
".",
"ClientStore",
")",
"(",
"string",
",",
"error",
")",
"{",
"modelController",
",",
"_",
":=",
"SplitModelName",
"(",
"os",
".",
"Getenv",
"(",
"osenv",
".",
"JujuModelEnvKey",
")",
")",
"\n",
"envController",
":=",
"os",
".",
"Getenv",
"(",
"osenv",
".",
"JujuControllerEnvKey",
")",
"\n",
"if",
"modelController",
"!=",
"\"",
"\"",
"&&",
"envController",
"!=",
"\"",
"\"",
"&&",
"modelController",
"!=",
"envController",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"osenv",
".",
"JujuModelEnvKey",
",",
"modelController",
",",
"osenv",
".",
"JujuControllerEnvKey",
",",
"envController",
",",
")",
"\n",
"}",
"\n",
"controllerName",
":=",
"modelController",
"\n",
"if",
"controllerName",
"==",
"\"",
"\"",
"{",
"controllerName",
"=",
"envController",
"\n",
"}",
"\n",
"if",
"controllerName",
"==",
"\"",
"\"",
"{",
"var",
"err",
"error",
"\n",
"controllerName",
",",
"err",
"=",
"store",
".",
"CurrentController",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"store",
".",
"ControllerByName",
"(",
"controllerName",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"controllerName",
",",
"nil",
"\n",
"}"
] | // DetermineCurrentController returns current controller on this client.
// It considers commandline flags, environment variables, and current config. | [
"DetermineCurrentController",
"returns",
"current",
"controller",
"on",
"this",
"client",
".",
"It",
"considers",
"commandline",
"flags",
"environment",
"variables",
"and",
"current",
"config",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/modelcmd/controller.go#L108-L133 |
155,051 | juju/juju | cmd/modelcmd/controller.go | SetControllerName | func (c *ControllerCommandBase) SetControllerName(controllerName string, allowDefault bool) error {
logger.Infof("setting controllerName to %q %v", controllerName, allowDefault)
c._controllerName = controllerName
c.allowDefaultController = allowDefault
if c.runStarted {
if err := c.initController(); err != nil {
return errors.Trace(err)
}
}
return nil
} | go | func (c *ControllerCommandBase) SetControllerName(controllerName string, allowDefault bool) error {
logger.Infof("setting controllerName to %q %v", controllerName, allowDefault)
c._controllerName = controllerName
c.allowDefaultController = allowDefault
if c.runStarted {
if err := c.initController(); err != nil {
return errors.Trace(err)
}
}
return nil
} | [
"func",
"(",
"c",
"*",
"ControllerCommandBase",
")",
"SetControllerName",
"(",
"controllerName",
"string",
",",
"allowDefault",
"bool",
")",
"error",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"controllerName",
",",
"allowDefault",
")",
"\n",
"c",
".",
"_controllerName",
"=",
"controllerName",
"\n",
"c",
".",
"allowDefaultController",
"=",
"allowDefault",
"\n",
"if",
"c",
".",
"runStarted",
"{",
"if",
"err",
":=",
"c",
".",
"initController",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SetControllerName implements ControllerCommand.SetControllerName. | [
"SetControllerName",
"implements",
"ControllerCommand",
".",
"SetControllerName",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/modelcmd/controller.go#L153-L163 |
155,052 | juju/juju | cmd/modelcmd/controller.go | ControllerName | func (c *ControllerCommandBase) ControllerName() (string, error) {
c.assertRunStarted()
if err := c.initController(); err != nil {
return "", errors.Trace(err)
}
return c._controllerName, nil
} | go | func (c *ControllerCommandBase) ControllerName() (string, error) {
c.assertRunStarted()
if err := c.initController(); err != nil {
return "", errors.Trace(err)
}
return c._controllerName, nil
} | [
"func",
"(",
"c",
"*",
"ControllerCommandBase",
")",
"ControllerName",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"c",
".",
"assertRunStarted",
"(",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"initController",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"_controllerName",
",",
"nil",
"\n",
"}"
] | // ControllerName implements the ControllerCommand interface. | [
"ControllerName",
"implements",
"the",
"ControllerCommand",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/modelcmd/controller.go#L166-L172 |
155,053 | juju/juju | cmd/modelcmd/controller.go | NewControllerAPIClient | func (c *ControllerCommandBase) NewControllerAPIClient() (*controller.Client, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return controller.NewClient(root), nil
} | go | func (c *ControllerCommandBase) NewControllerAPIClient() (*controller.Client, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return controller.NewClient(root), nil
} | [
"func",
"(",
"c",
"*",
"ControllerCommandBase",
")",
"NewControllerAPIClient",
"(",
")",
"(",
"*",
"controller",
".",
"Client",
",",
"error",
")",
"{",
"root",
",",
"err",
":=",
"c",
".",
"NewAPIRoot",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"controller",
".",
"NewClient",
"(",
"root",
")",
",",
"nil",
"\n",
"}"
] | // NewControllerAPIClient returns an API client for the Controller on
// the current controller using the current credentials. | [
"NewControllerAPIClient",
"returns",
"an",
"API",
"client",
"for",
"the",
"Controller",
"on",
"the",
"current",
"controller",
"using",
"the",
"current",
"credentials",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/modelcmd/controller.go#L202-L208 |
155,054 | juju/juju | cmd/modelcmd/controller.go | NewUserManagerAPIClient | func (c *ControllerCommandBase) NewUserManagerAPIClient() (*usermanager.Client, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return usermanager.NewClient(root), nil
} | go | func (c *ControllerCommandBase) NewUserManagerAPIClient() (*usermanager.Client, error) {
root, err := c.NewAPIRoot()
if err != nil {
return nil, errors.Trace(err)
}
return usermanager.NewClient(root), nil
} | [
"func",
"(",
"c",
"*",
"ControllerCommandBase",
")",
"NewUserManagerAPIClient",
"(",
")",
"(",
"*",
"usermanager",
".",
"Client",
",",
"error",
")",
"{",
"root",
",",
"err",
":=",
"c",
".",
"NewAPIRoot",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"usermanager",
".",
"NewClient",
"(",
"root",
")",
",",
"nil",
"\n",
"}"
] | // NewUserManagerAPIClient returns an API client for the UserManager on the
// current controller using the current credentials. | [
"NewUserManagerAPIClient",
"returns",
"an",
"API",
"client",
"for",
"the",
"UserManager",
"on",
"the",
"current",
"controller",
"using",
"the",
"current",
"credentials",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/modelcmd/controller.go#L212-L218 |
155,055 | juju/juju | cmd/modelcmd/controller.go | NewModelAPIRoot | func (c *ControllerCommandBase) NewModelAPIRoot(modelName string) (api.Connection, error) {
controllerName, err := c.ControllerName()
if err != nil {
return nil, errors.Trace(err)
}
_, err = c.store.ModelByName(controllerName, modelName)
if err != nil {
if !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
// The model isn't known locally, so query the models
// available in the controller, and cache them locally.
if err := c.RefreshModels(c.store, controllerName); err != nil {
return nil, errors.Annotate(err, "refreshing models")
}
}
return c.newAPIRoot(modelName)
} | go | func (c *ControllerCommandBase) NewModelAPIRoot(modelName string) (api.Connection, error) {
controllerName, err := c.ControllerName()
if err != nil {
return nil, errors.Trace(err)
}
_, err = c.store.ModelByName(controllerName, modelName)
if err != nil {
if !errors.IsNotFound(err) {
return nil, errors.Trace(err)
}
// The model isn't known locally, so query the models
// available in the controller, and cache them locally.
if err := c.RefreshModels(c.store, controllerName); err != nil {
return nil, errors.Annotate(err, "refreshing models")
}
}
return c.newAPIRoot(modelName)
} | [
"func",
"(",
"c",
"*",
"ControllerCommandBase",
")",
"NewModelAPIRoot",
"(",
"modelName",
"string",
")",
"(",
"api",
".",
"Connection",
",",
"error",
")",
"{",
"controllerName",
",",
"err",
":=",
"c",
".",
"ControllerName",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"c",
".",
"store",
".",
"ModelByName",
"(",
"controllerName",
",",
"modelName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"!",
"errors",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"// The model isn't known locally, so query the models",
"// available in the controller, and cache them locally.",
"if",
"err",
":=",
"c",
".",
"RefreshModels",
"(",
"c",
".",
"store",
",",
"controllerName",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"c",
".",
"newAPIRoot",
"(",
"modelName",
")",
"\n",
"}"
] | // NewAPIRoot returns a new connection to the API server for the named model
// in the specified controller. | [
"NewAPIRoot",
"returns",
"a",
"new",
"connection",
"to",
"the",
"API",
"server",
"for",
"the",
"named",
"model",
"in",
"the",
"specified",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/modelcmd/controller.go#L229-L246 |
155,056 | juju/juju | cmd/modelcmd/controller.go | CurrentAccountDetails | func (c *ControllerCommandBase) CurrentAccountDetails() (*jujuclient.AccountDetails, error) {
controllerName, err := c.ControllerName()
if err != nil {
return nil, errors.Trace(err)
}
return c.ClientStore().AccountDetails(controllerName)
} | go | func (c *ControllerCommandBase) CurrentAccountDetails() (*jujuclient.AccountDetails, error) {
controllerName, err := c.ControllerName()
if err != nil {
return nil, errors.Trace(err)
}
return c.ClientStore().AccountDetails(controllerName)
} | [
"func",
"(",
"c",
"*",
"ControllerCommandBase",
")",
"CurrentAccountDetails",
"(",
")",
"(",
"*",
"jujuclient",
".",
"AccountDetails",
",",
"error",
")",
"{",
"controllerName",
",",
"err",
":=",
"c",
".",
"ControllerName",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"ClientStore",
"(",
")",
".",
"AccountDetails",
"(",
"controllerName",
")",
"\n",
"}"
] | // CurrentAccountDetails returns details of the account associated with
// the current controller. | [
"CurrentAccountDetails",
"returns",
"details",
"of",
"the",
"account",
"associated",
"with",
"the",
"current",
"controller",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/modelcmd/controller.go#L267-L273 |
155,057 | juju/juju | cmd/modelcmd/controller.go | WrapController | func WrapController(c ControllerCommand, options ...WrapControllerOption) ControllerCommand {
wrapper := &controllerCommandWrapper{
ControllerCommand: c,
setControllerFlags: true,
useDefaultController: true,
}
for _, option := range options {
option(wrapper)
}
// Define a new type so that we can embed the ModelCommand
// interface one level deeper than cmd.Command, so that
// we'll get the Command methods from WrapBase
// and all the ModelCommand methods not in cmd.Command
// from modelCommandWrapper.
type embed struct {
*controllerCommandWrapper
}
return struct {
embed
cmd.Command
}{
Command: WrapBase(wrapper),
embed: embed{wrapper},
}
} | go | func WrapController(c ControllerCommand, options ...WrapControllerOption) ControllerCommand {
wrapper := &controllerCommandWrapper{
ControllerCommand: c,
setControllerFlags: true,
useDefaultController: true,
}
for _, option := range options {
option(wrapper)
}
// Define a new type so that we can embed the ModelCommand
// interface one level deeper than cmd.Command, so that
// we'll get the Command methods from WrapBase
// and all the ModelCommand methods not in cmd.Command
// from modelCommandWrapper.
type embed struct {
*controllerCommandWrapper
}
return struct {
embed
cmd.Command
}{
Command: WrapBase(wrapper),
embed: embed{wrapper},
}
} | [
"func",
"WrapController",
"(",
"c",
"ControllerCommand",
",",
"options",
"...",
"WrapControllerOption",
")",
"ControllerCommand",
"{",
"wrapper",
":=",
"&",
"controllerCommandWrapper",
"{",
"ControllerCommand",
":",
"c",
",",
"setControllerFlags",
":",
"true",
",",
"useDefaultController",
":",
"true",
",",
"}",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"options",
"{",
"option",
"(",
"wrapper",
")",
"\n",
"}",
"\n",
"// Define a new type so that we can embed the ModelCommand",
"// interface one level deeper than cmd.Command, so that",
"// we'll get the Command methods from WrapBase",
"// and all the ModelCommand methods not in cmd.Command",
"// from modelCommandWrapper.",
"type",
"embed",
"struct",
"{",
"*",
"controllerCommandWrapper",
"\n",
"}",
"\n",
"return",
"struct",
"{",
"embed",
"\n",
"cmd",
".",
"Command",
"\n",
"}",
"{",
"Command",
":",
"WrapBase",
"(",
"wrapper",
")",
",",
"embed",
":",
"embed",
"{",
"wrapper",
"}",
",",
"}",
"\n",
"}"
] | // WrapController wraps the specified ControllerCommand, returning a Command
// that proxies to each of the ControllerCommand methods. | [
"WrapController",
"wraps",
"the",
"specified",
"ControllerCommand",
"returning",
"a",
"Command",
"that",
"proxies",
"to",
"each",
"of",
"the",
"ControllerCommand",
"methods",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/modelcmd/controller.go#L299-L323 |
155,058 | juju/juju | cmd/modelcmd/controller.go | SetFlags | func (w *controllerCommandWrapper) SetFlags(f *gnuflag.FlagSet) {
if w.setControllerFlags {
f.StringVar(&w.controllerName, "c", "", "Controller to operate in")
f.StringVar(&w.controllerName, "controller", "", "")
}
w.ControllerCommand.SetFlags(f)
} | go | func (w *controllerCommandWrapper) SetFlags(f *gnuflag.FlagSet) {
if w.setControllerFlags {
f.StringVar(&w.controllerName, "c", "", "Controller to operate in")
f.StringVar(&w.controllerName, "controller", "", "")
}
w.ControllerCommand.SetFlags(f)
} | [
"func",
"(",
"w",
"*",
"controllerCommandWrapper",
")",
"SetFlags",
"(",
"f",
"*",
"gnuflag",
".",
"FlagSet",
")",
"{",
"if",
"w",
".",
"setControllerFlags",
"{",
"f",
".",
"StringVar",
"(",
"&",
"w",
".",
"controllerName",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"f",
".",
"StringVar",
"(",
"&",
"w",
".",
"controllerName",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"w",
".",
"ControllerCommand",
".",
"SetFlags",
"(",
"f",
")",
"\n",
"}"
] | // SetFlags implements Command.SetFlags, then calls the wrapped command's SetFlags. | [
"SetFlags",
"implements",
"Command",
".",
"SetFlags",
"then",
"calls",
"the",
"wrapped",
"command",
"s",
"SetFlags",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/modelcmd/controller.go#L338-L344 |
155,059 | juju/juju | cmd/modelcmd/controller.go | Init | func (w *controllerCommandWrapper) Init(args []string) error {
if w.setControllerFlags {
if err := w.SetControllerName(w.controllerName, w.useDefaultController); err != nil {
return errors.Trace(err)
}
}
if err := w.ControllerCommand.Init(args); err != nil {
return errors.Trace(err)
}
return nil
} | go | func (w *controllerCommandWrapper) Init(args []string) error {
if w.setControllerFlags {
if err := w.SetControllerName(w.controllerName, w.useDefaultController); err != nil {
return errors.Trace(err)
}
}
if err := w.ControllerCommand.Init(args); err != nil {
return errors.Trace(err)
}
return nil
} | [
"func",
"(",
"w",
"*",
"controllerCommandWrapper",
")",
"Init",
"(",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"w",
".",
"setControllerFlags",
"{",
"if",
"err",
":=",
"w",
".",
"SetControllerName",
"(",
"w",
".",
"controllerName",
",",
"w",
".",
"useDefaultController",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"w",
".",
"ControllerCommand",
".",
"Init",
"(",
"args",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Init implements Command.Init, then calls the wrapped command's Init. | [
"Init",
"implements",
"Command",
".",
"Init",
"then",
"calls",
"the",
"wrapped",
"command",
"s",
"Init",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/modelcmd/controller.go#L347-L357 |
155,060 | juju/juju | api/backups/download.go | Download | func (c *Client) Download(id string) (io.ReadCloser, error) {
// Send the request.
var resp *http.Response
err := c.client.Call(
&downloadParams{
Body: params.BackupsDownloadArgs{
ID: id,
},
},
&resp,
)
if err != nil {
return nil, errors.Trace(err)
}
return resp.Body, nil
} | go | func (c *Client) Download(id string) (io.ReadCloser, error) {
// Send the request.
var resp *http.Response
err := c.client.Call(
&downloadParams{
Body: params.BackupsDownloadArgs{
ID: id,
},
},
&resp,
)
if err != nil {
return nil, errors.Trace(err)
}
return resp.Body, nil
} | [
"func",
"(",
"c",
"*",
"Client",
")",
"Download",
"(",
"id",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"// Send the request.",
"var",
"resp",
"*",
"http",
".",
"Response",
"\n",
"err",
":=",
"c",
".",
"client",
".",
"Call",
"(",
"&",
"downloadParams",
"{",
"Body",
":",
"params",
".",
"BackupsDownloadArgs",
"{",
"ID",
":",
"id",
",",
"}",
",",
"}",
",",
"&",
"resp",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"resp",
".",
"Body",
",",
"nil",
"\n",
"}"
] | // Download returns an io.ReadCloser for the given backup id. | [
"Download",
"returns",
"an",
"io",
".",
"ReadCloser",
"for",
"the",
"given",
"backup",
"id",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/api/backups/download.go#L22-L37 |
155,061 | juju/juju | worker/leadership/tracker.go | refresh | func (t *Tracker) refresh() error {
logger.Tracef("checking %s for %s leadership", t.unitName, t.applicationName)
leaseDuration := 2 * t.duration
untilTime := t.clock.Now().Add(leaseDuration)
err := t.claimer.ClaimLeadership(t.applicationName, t.unitName, leaseDuration)
switch {
case err == nil:
return t.setLeader(untilTime)
case errors.Cause(err) == leadership.ErrClaimDenied:
return t.setMinion()
}
return errors.Annotatef(err, "leadership failure")
} | go | func (t *Tracker) refresh() error {
logger.Tracef("checking %s for %s leadership", t.unitName, t.applicationName)
leaseDuration := 2 * t.duration
untilTime := t.clock.Now().Add(leaseDuration)
err := t.claimer.ClaimLeadership(t.applicationName, t.unitName, leaseDuration)
switch {
case err == nil:
return t.setLeader(untilTime)
case errors.Cause(err) == leadership.ErrClaimDenied:
return t.setMinion()
}
return errors.Annotatef(err, "leadership failure")
} | [
"func",
"(",
"t",
"*",
"Tracker",
")",
"refresh",
"(",
")",
"error",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
")",
"\n",
"leaseDuration",
":=",
"2",
"*",
"t",
".",
"duration",
"\n",
"untilTime",
":=",
"t",
".",
"clock",
".",
"Now",
"(",
")",
".",
"Add",
"(",
"leaseDuration",
")",
"\n",
"err",
":=",
"t",
".",
"claimer",
".",
"ClaimLeadership",
"(",
"t",
".",
"applicationName",
",",
"t",
".",
"unitName",
",",
"leaseDuration",
")",
"\n",
"switch",
"{",
"case",
"err",
"==",
"nil",
":",
"return",
"t",
".",
"setLeader",
"(",
"untilTime",
")",
"\n",
"case",
"errors",
".",
"Cause",
"(",
"err",
")",
"==",
"leadership",
".",
"ErrClaimDenied",
":",
"return",
"t",
".",
"setMinion",
"(",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Annotatef",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // refresh makes a leadership request, and updates Tracker state to conform to
// latest known reality. | [
"refresh",
"makes",
"a",
"leadership",
"request",
"and",
"updates",
"Tracker",
"state",
"to",
"conform",
"to",
"latest",
"known",
"reality",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/leadership/tracker.go#L181-L193 |
155,062 | juju/juju | worker/leadership/tracker.go | setLeader | func (t *Tracker) setLeader(untilTime time.Time) error {
if t.isMinion {
// If we were a minion, we're now the leader, so we can record the transition.
logger.Infof("%s promoted to leadership of %s", t.unitName, t.applicationName)
}
logger.Tracef("%s confirmed for %s leadership until %s", t.unitName, t.applicationName, untilTime)
renewTime := untilTime.Add(-t.duration)
logger.Tracef("%s will renew %s leadership at %s", t.unitName, t.applicationName, renewTime)
t.isMinion = false
t.claimLease = nil
t.renewLease = t.clock.After(renewTime.Sub(t.clock.Now()))
for len(t.waitingLeader) > 0 {
logger.Tracef("notifying %s ticket of impending %s leadership", t.unitName, t.applicationName)
var ticketCh chan bool
ticketCh, t.waitingLeader = t.waitingLeader[0], t.waitingLeader[1:]
defer close(ticketCh)
if err := t.sendTrue(ticketCh); err != nil {
return errors.Trace(err)
}
}
return nil
} | go | func (t *Tracker) setLeader(untilTime time.Time) error {
if t.isMinion {
// If we were a minion, we're now the leader, so we can record the transition.
logger.Infof("%s promoted to leadership of %s", t.unitName, t.applicationName)
}
logger.Tracef("%s confirmed for %s leadership until %s", t.unitName, t.applicationName, untilTime)
renewTime := untilTime.Add(-t.duration)
logger.Tracef("%s will renew %s leadership at %s", t.unitName, t.applicationName, renewTime)
t.isMinion = false
t.claimLease = nil
t.renewLease = t.clock.After(renewTime.Sub(t.clock.Now()))
for len(t.waitingLeader) > 0 {
logger.Tracef("notifying %s ticket of impending %s leadership", t.unitName, t.applicationName)
var ticketCh chan bool
ticketCh, t.waitingLeader = t.waitingLeader[0], t.waitingLeader[1:]
defer close(ticketCh)
if err := t.sendTrue(ticketCh); err != nil {
return errors.Trace(err)
}
}
return nil
} | [
"func",
"(",
"t",
"*",
"Tracker",
")",
"setLeader",
"(",
"untilTime",
"time",
".",
"Time",
")",
"error",
"{",
"if",
"t",
".",
"isMinion",
"{",
"// If we were a minion, we're now the leader, so we can record the transition.",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
")",
"\n",
"}",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
",",
"untilTime",
")",
"\n",
"renewTime",
":=",
"untilTime",
".",
"Add",
"(",
"-",
"t",
".",
"duration",
")",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
",",
"renewTime",
")",
"\n",
"t",
".",
"isMinion",
"=",
"false",
"\n",
"t",
".",
"claimLease",
"=",
"nil",
"\n",
"t",
".",
"renewLease",
"=",
"t",
".",
"clock",
".",
"After",
"(",
"renewTime",
".",
"Sub",
"(",
"t",
".",
"clock",
".",
"Now",
"(",
")",
")",
")",
"\n\n",
"for",
"len",
"(",
"t",
".",
"waitingLeader",
")",
">",
"0",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
")",
"\n",
"var",
"ticketCh",
"chan",
"bool",
"\n",
"ticketCh",
",",
"t",
".",
"waitingLeader",
"=",
"t",
".",
"waitingLeader",
"[",
"0",
"]",
",",
"t",
".",
"waitingLeader",
"[",
"1",
":",
"]",
"\n",
"defer",
"close",
"(",
"ticketCh",
")",
"\n",
"if",
"err",
":=",
"t",
".",
"sendTrue",
"(",
"ticketCh",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // setLeader arranges for lease renewal. | [
"setLeader",
"arranges",
"for",
"lease",
"renewal",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/leadership/tracker.go#L196-L218 |
155,063 | juju/juju | worker/leadership/tracker.go | setMinion | func (t *Tracker) setMinion() error {
logger.Infof("%s leadership for %s denied", t.applicationName, t.unitName)
t.isMinion = true
t.renewLease = nil
if t.claimLease == nil {
t.claimLease = make(chan error, 1)
go func() {
defer close(t.claimLease)
logger.Debugf("%s waiting for %s leadership release", t.unitName, t.applicationName)
err := t.claimer.BlockUntilLeadershipReleased(t.applicationName, t.tomb.Dying())
t.claimLease <- err
}()
}
for len(t.waitingMinion) > 0 {
logger.Debugf("notifying %s ticket of impending loss of %s leadership", t.unitName, t.applicationName)
var ticketCh chan bool
ticketCh, t.waitingMinion = t.waitingMinion[0], t.waitingMinion[1:]
defer close(ticketCh)
if err := t.sendTrue(ticketCh); err != nil {
return errors.Trace(err)
}
}
return nil
} | go | func (t *Tracker) setMinion() error {
logger.Infof("%s leadership for %s denied", t.applicationName, t.unitName)
t.isMinion = true
t.renewLease = nil
if t.claimLease == nil {
t.claimLease = make(chan error, 1)
go func() {
defer close(t.claimLease)
logger.Debugf("%s waiting for %s leadership release", t.unitName, t.applicationName)
err := t.claimer.BlockUntilLeadershipReleased(t.applicationName, t.tomb.Dying())
t.claimLease <- err
}()
}
for len(t.waitingMinion) > 0 {
logger.Debugf("notifying %s ticket of impending loss of %s leadership", t.unitName, t.applicationName)
var ticketCh chan bool
ticketCh, t.waitingMinion = t.waitingMinion[0], t.waitingMinion[1:]
defer close(ticketCh)
if err := t.sendTrue(ticketCh); err != nil {
return errors.Trace(err)
}
}
return nil
} | [
"func",
"(",
"t",
"*",
"Tracker",
")",
"setMinion",
"(",
")",
"error",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"t",
".",
"applicationName",
",",
"t",
".",
"unitName",
")",
"\n",
"t",
".",
"isMinion",
"=",
"true",
"\n",
"t",
".",
"renewLease",
"=",
"nil",
"\n",
"if",
"t",
".",
"claimLease",
"==",
"nil",
"{",
"t",
".",
"claimLease",
"=",
"make",
"(",
"chan",
"error",
",",
"1",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"close",
"(",
"t",
".",
"claimLease",
")",
"\n",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
")",
"\n",
"err",
":=",
"t",
".",
"claimer",
".",
"BlockUntilLeadershipReleased",
"(",
"t",
".",
"applicationName",
",",
"t",
".",
"tomb",
".",
"Dying",
"(",
")",
")",
"\n",
"t",
".",
"claimLease",
"<-",
"err",
"\n",
"}",
"(",
")",
"\n",
"}",
"\n\n",
"for",
"len",
"(",
"t",
".",
"waitingMinion",
")",
">",
"0",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
")",
"\n",
"var",
"ticketCh",
"chan",
"bool",
"\n",
"ticketCh",
",",
"t",
".",
"waitingMinion",
"=",
"t",
".",
"waitingMinion",
"[",
"0",
"]",
",",
"t",
".",
"waitingMinion",
"[",
"1",
":",
"]",
"\n",
"defer",
"close",
"(",
"ticketCh",
")",
"\n",
"if",
"err",
":=",
"t",
".",
"sendTrue",
"(",
"ticketCh",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // setMinion arranges for lease acquisition when there's an opportunity. | [
"setMinion",
"arranges",
"for",
"lease",
"acquisition",
"when",
"there",
"s",
"an",
"opportunity",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/leadership/tracker.go#L221-L245 |
155,064 | juju/juju | worker/leadership/tracker.go | isLeader | func (t *Tracker) isLeader() (bool, error) {
if !t.isMinion {
// Last time we looked, we were leader.
select {
case <-t.tomb.Dying():
return false, errors.Trace(tomb.ErrDying)
case <-t.renewLease:
logger.Tracef("%s renewing lease for %s leadership", t.unitName, t.applicationName)
t.renewLease = nil
if err := t.refresh(); err != nil {
return false, errors.Trace(err)
}
default:
logger.Tracef("%s still has %s leadership", t.unitName, t.applicationName)
}
}
return !t.isMinion, nil
} | go | func (t *Tracker) isLeader() (bool, error) {
if !t.isMinion {
// Last time we looked, we were leader.
select {
case <-t.tomb.Dying():
return false, errors.Trace(tomb.ErrDying)
case <-t.renewLease:
logger.Tracef("%s renewing lease for %s leadership", t.unitName, t.applicationName)
t.renewLease = nil
if err := t.refresh(); err != nil {
return false, errors.Trace(err)
}
default:
logger.Tracef("%s still has %s leadership", t.unitName, t.applicationName)
}
}
return !t.isMinion, nil
} | [
"func",
"(",
"t",
"*",
"Tracker",
")",
"isLeader",
"(",
")",
"(",
"bool",
",",
"error",
")",
"{",
"if",
"!",
"t",
".",
"isMinion",
"{",
"// Last time we looked, we were leader.",
"select",
"{",
"case",
"<-",
"t",
".",
"tomb",
".",
"Dying",
"(",
")",
":",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"tomb",
".",
"ErrDying",
")",
"\n",
"case",
"<-",
"t",
".",
"renewLease",
":",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
")",
"\n",
"t",
".",
"renewLease",
"=",
"nil",
"\n",
"if",
"err",
":=",
"t",
".",
"refresh",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"default",
":",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"!",
"t",
".",
"isMinion",
",",
"nil",
"\n",
"}"
] | // isLeader returns true if leadership is guaranteed for the Tracker's duration. | [
"isLeader",
"returns",
"true",
"if",
"leadership",
"is",
"guaranteed",
"for",
"the",
"Tracker",
"s",
"duration",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/leadership/tracker.go#L248-L265 |
155,065 | juju/juju | worker/leadership/tracker.go | resolveClaim | func (t *Tracker) resolveClaim(ticketCh chan bool) error {
logger.Tracef("resolving %s leadership ticket for %s...", t.applicationName, t.unitName)
defer close(ticketCh)
if leader, err := t.isLeader(); err != nil {
return errors.Trace(err)
} else if !leader {
logger.Debugf("%s is not %s leader", t.unitName, t.applicationName)
return nil
}
logger.Tracef("confirming %s leadership for %s", t.applicationName, t.unitName)
return t.sendTrue(ticketCh)
} | go | func (t *Tracker) resolveClaim(ticketCh chan bool) error {
logger.Tracef("resolving %s leadership ticket for %s...", t.applicationName, t.unitName)
defer close(ticketCh)
if leader, err := t.isLeader(); err != nil {
return errors.Trace(err)
} else if !leader {
logger.Debugf("%s is not %s leader", t.unitName, t.applicationName)
return nil
}
logger.Tracef("confirming %s leadership for %s", t.applicationName, t.unitName)
return t.sendTrue(ticketCh)
} | [
"func",
"(",
"t",
"*",
"Tracker",
")",
"resolveClaim",
"(",
"ticketCh",
"chan",
"bool",
")",
"error",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"applicationName",
",",
"t",
".",
"unitName",
")",
"\n",
"defer",
"close",
"(",
"ticketCh",
")",
"\n",
"if",
"leader",
",",
"err",
":=",
"t",
".",
"isLeader",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"else",
"if",
"!",
"leader",
"{",
"logger",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"applicationName",
",",
"t",
".",
"unitName",
")",
"\n",
"return",
"t",
".",
"sendTrue",
"(",
"ticketCh",
")",
"\n",
"}"
] | // resolveClaim will send true on the supplied channel if leadership can be
// successfully verified, and will always close it whether or not it sent. | [
"resolveClaim",
"will",
"send",
"true",
"on",
"the",
"supplied",
"channel",
"if",
"leadership",
"can",
"be",
"successfully",
"verified",
"and",
"will",
"always",
"close",
"it",
"whether",
"or",
"not",
"it",
"sent",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/leadership/tracker.go#L269-L280 |
155,066 | juju/juju | worker/leadership/tracker.go | resolveWaitLeader | func (t *Tracker) resolveWaitLeader(ticketCh chan bool) error {
var dontClose bool
defer func() {
if !dontClose {
close(ticketCh)
}
}()
if leader, err := t.isLeader(); err != nil {
return errors.Trace(err)
} else if leader {
logger.Tracef("reporting %s leadership for %s", t.applicationName, t.unitName)
return t.sendTrue(ticketCh)
}
logger.Tracef("waiting for %s to attain %s leadership", t.unitName, t.applicationName)
t.waitingLeader = append(t.waitingLeader, ticketCh)
dontClose = true
return nil
} | go | func (t *Tracker) resolveWaitLeader(ticketCh chan bool) error {
var dontClose bool
defer func() {
if !dontClose {
close(ticketCh)
}
}()
if leader, err := t.isLeader(); err != nil {
return errors.Trace(err)
} else if leader {
logger.Tracef("reporting %s leadership for %s", t.applicationName, t.unitName)
return t.sendTrue(ticketCh)
}
logger.Tracef("waiting for %s to attain %s leadership", t.unitName, t.applicationName)
t.waitingLeader = append(t.waitingLeader, ticketCh)
dontClose = true
return nil
} | [
"func",
"(",
"t",
"*",
"Tracker",
")",
"resolveWaitLeader",
"(",
"ticketCh",
"chan",
"bool",
")",
"error",
"{",
"var",
"dontClose",
"bool",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"!",
"dontClose",
"{",
"close",
"(",
"ticketCh",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"leader",
",",
"err",
":=",
"t",
".",
"isLeader",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"else",
"if",
"leader",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"applicationName",
",",
"t",
".",
"unitName",
")",
"\n",
"return",
"t",
".",
"sendTrue",
"(",
"ticketCh",
")",
"\n",
"}",
"\n\n",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
")",
"\n",
"t",
".",
"waitingLeader",
"=",
"append",
"(",
"t",
".",
"waitingLeader",
",",
"ticketCh",
")",
"\n",
"dontClose",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] | // resolveWaitLeader will send true on the supplied channel if leadership can be
// guaranteed for the Tracker's duration. It will then close the channel. If
// leadership cannot be guaranteed, the channel is left untouched until either
// the termination of the Tracker or the next invocation of setLeader; at which
// point true is sent if applicable, and the channel is closed. | [
"resolveWaitLeader",
"will",
"send",
"true",
"on",
"the",
"supplied",
"channel",
"if",
"leadership",
"can",
"be",
"guaranteed",
"for",
"the",
"Tracker",
"s",
"duration",
".",
"It",
"will",
"then",
"close",
"the",
"channel",
".",
"If",
"leadership",
"cannot",
"be",
"guaranteed",
"the",
"channel",
"is",
"left",
"untouched",
"until",
"either",
"the",
"termination",
"of",
"the",
"Tracker",
"or",
"the",
"next",
"invocation",
"of",
"setLeader",
";",
"at",
"which",
"point",
"true",
"is",
"sent",
"if",
"applicable",
"and",
"the",
"channel",
"is",
"closed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/leadership/tracker.go#L287-L306 |
155,067 | juju/juju | worker/leadership/tracker.go | resolveWaitMinion | func (t *Tracker) resolveWaitMinion(ticketCh chan bool) error {
var dontClose bool
defer func() {
if !dontClose {
close(ticketCh)
}
}()
if leader, err := t.isLeader(); err != nil {
return errors.Trace(err)
} else if leader {
logger.Tracef("waiting for %s to lose %s leadership", t.unitName, t.applicationName)
t.waitingMinion = append(t.waitingMinion, ticketCh)
dontClose = true
} else {
logger.Tracef("reporting %s leadership loss for %s", t.applicationName, t.unitName)
}
return nil
} | go | func (t *Tracker) resolveWaitMinion(ticketCh chan bool) error {
var dontClose bool
defer func() {
if !dontClose {
close(ticketCh)
}
}()
if leader, err := t.isLeader(); err != nil {
return errors.Trace(err)
} else if leader {
logger.Tracef("waiting for %s to lose %s leadership", t.unitName, t.applicationName)
t.waitingMinion = append(t.waitingMinion, ticketCh)
dontClose = true
} else {
logger.Tracef("reporting %s leadership loss for %s", t.applicationName, t.unitName)
}
return nil
} | [
"func",
"(",
"t",
"*",
"Tracker",
")",
"resolveWaitMinion",
"(",
"ticketCh",
"chan",
"bool",
")",
"error",
"{",
"var",
"dontClose",
"bool",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"!",
"dontClose",
"{",
"close",
"(",
"ticketCh",
")",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"if",
"leader",
",",
"err",
":=",
"t",
".",
"isLeader",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"else",
"if",
"leader",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"unitName",
",",
"t",
".",
"applicationName",
")",
"\n",
"t",
".",
"waitingMinion",
"=",
"append",
"(",
"t",
".",
"waitingMinion",
",",
"ticketCh",
")",
"\n",
"dontClose",
"=",
"true",
"\n",
"}",
"else",
"{",
"logger",
".",
"Tracef",
"(",
"\"",
"\"",
",",
"t",
".",
"applicationName",
",",
"t",
".",
"unitName",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n\n",
"}"
] | // resolveWaitMinion will close the supplied channel as soon as leadership cannot
// be guaranteed beyond the Tracker's duration. | [
"resolveWaitMinion",
"will",
"close",
"the",
"supplied",
"channel",
"as",
"soon",
"as",
"leadership",
"cannot",
"be",
"guaranteed",
"beyond",
"the",
"Tracker",
"s",
"duration",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/leadership/tracker.go#L310-L329 |
155,068 | juju/juju | apiserver/common/instancetypes.go | NewInstanceTypeConstraints | func NewInstanceTypeConstraints(env environs.Environ, ctx context.ProviderCallContext, constraints constraints.Value) instanceTypeConstraints {
return instanceTypeConstraints{
environ: env,
constraints: constraints,
context: ctx,
}
} | go | func NewInstanceTypeConstraints(env environs.Environ, ctx context.ProviderCallContext, constraints constraints.Value) instanceTypeConstraints {
return instanceTypeConstraints{
environ: env,
constraints: constraints,
context: ctx,
}
} | [
"func",
"NewInstanceTypeConstraints",
"(",
"env",
"environs",
".",
"Environ",
",",
"ctx",
"context",
".",
"ProviderCallContext",
",",
"constraints",
"constraints",
".",
"Value",
")",
"instanceTypeConstraints",
"{",
"return",
"instanceTypeConstraints",
"{",
"environ",
":",
"env",
",",
"constraints",
":",
"constraints",
",",
"context",
":",
"ctx",
",",
"}",
"\n",
"}"
] | // NewInstanceTypeConstraints returns an instanceTypeConstraints with the passed
// parameters. | [
"NewInstanceTypeConstraints",
"returns",
"an",
"instanceTypeConstraints",
"with",
"the",
"passed",
"parameters",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/instancetypes.go#L39-L45 |
155,069 | juju/juju | apiserver/common/instancetypes.go | InstanceTypes | func InstanceTypes(cons instanceTypeConstraints) (params.InstanceTypesResult, error) {
instanceTypes, err := cons.environ.InstanceTypes(cons.context, cons.constraints)
if err != nil {
return params.InstanceTypesResult{}, errors.Trace(err)
}
return params.InstanceTypesResult{
InstanceTypes: toParamsInstanceTypeResult(instanceTypes.InstanceTypes),
CostUnit: instanceTypes.CostUnit,
CostCurrency: instanceTypes.CostCurrency,
CostDivisor: instanceTypes.CostDivisor,
}, nil
} | go | func InstanceTypes(cons instanceTypeConstraints) (params.InstanceTypesResult, error) {
instanceTypes, err := cons.environ.InstanceTypes(cons.context, cons.constraints)
if err != nil {
return params.InstanceTypesResult{}, errors.Trace(err)
}
return params.InstanceTypesResult{
InstanceTypes: toParamsInstanceTypeResult(instanceTypes.InstanceTypes),
CostUnit: instanceTypes.CostUnit,
CostCurrency: instanceTypes.CostCurrency,
CostDivisor: instanceTypes.CostDivisor,
}, nil
} | [
"func",
"InstanceTypes",
"(",
"cons",
"instanceTypeConstraints",
")",
"(",
"params",
".",
"InstanceTypesResult",
",",
"error",
")",
"{",
"instanceTypes",
",",
"err",
":=",
"cons",
".",
"environ",
".",
"InstanceTypes",
"(",
"cons",
".",
"context",
",",
"cons",
".",
"constraints",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"params",
".",
"InstanceTypesResult",
"{",
"}",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"params",
".",
"InstanceTypesResult",
"{",
"InstanceTypes",
":",
"toParamsInstanceTypeResult",
"(",
"instanceTypes",
".",
"InstanceTypes",
")",
",",
"CostUnit",
":",
"instanceTypes",
".",
"CostUnit",
",",
"CostCurrency",
":",
"instanceTypes",
".",
"CostCurrency",
",",
"CostDivisor",
":",
"instanceTypes",
".",
"CostDivisor",
",",
"}",
",",
"nil",
"\n",
"}"
] | // InstanceTypes returns a list of the available instance types in the provider according
// to the passed constraints. | [
"InstanceTypes",
"returns",
"a",
"list",
"of",
"the",
"available",
"instance",
"types",
"in",
"the",
"provider",
"according",
"to",
"the",
"passed",
"constraints",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/instancetypes.go#L56-L68 |
155,070 | juju/juju | provider/lxd/server.go | NewServerFactory | func NewServerFactory() ServerFactory {
return &serverFactory{
newLocalServerFunc: func() (Server, error) {
return lxd.NewLocalServer()
},
newRemoteServerFunc: func(spec lxd.ServerSpec) (Server, error) {
return lxd.NewRemoteServer(spec)
},
interfaceAddress: interfaceAddress{},
}
} | go | func NewServerFactory() ServerFactory {
return &serverFactory{
newLocalServerFunc: func() (Server, error) {
return lxd.NewLocalServer()
},
newRemoteServerFunc: func(spec lxd.ServerSpec) (Server, error) {
return lxd.NewRemoteServer(spec)
},
interfaceAddress: interfaceAddress{},
}
} | [
"func",
"NewServerFactory",
"(",
")",
"ServerFactory",
"{",
"return",
"&",
"serverFactory",
"{",
"newLocalServerFunc",
":",
"func",
"(",
")",
"(",
"Server",
",",
"error",
")",
"{",
"return",
"lxd",
".",
"NewLocalServer",
"(",
")",
"\n",
"}",
",",
"newRemoteServerFunc",
":",
"func",
"(",
"spec",
"lxd",
".",
"ServerSpec",
")",
"(",
"Server",
",",
"error",
")",
"{",
"return",
"lxd",
".",
"NewRemoteServer",
"(",
"spec",
")",
"\n",
"}",
",",
"interfaceAddress",
":",
"interfaceAddress",
"{",
"}",
",",
"}",
"\n",
"}"
] | // NewServerFactory creates a new ServerFactory with sane defaults. | [
"NewServerFactory",
"creates",
"a",
"new",
"ServerFactory",
"with",
"sane",
"defaults",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/server.go#L132-L142 |
155,071 | juju/juju | provider/lxd/server.go | isSupportedAPIVersion | func isSupportedAPIVersion(version string) (msg string, ok bool) {
versionParts := strings.Split(version, ".")
if len(versionParts) < 2 {
return fmt.Sprintf("LXD API version %q: expected format <major>.<minor>", version), false
}
major, err := strconv.Atoi(versionParts[0])
if err != nil {
return fmt.Sprintf("LXD API version %q: unexpected major number: %v", version, err), false
}
if major < 1 {
return fmt.Sprintf("LXD API version %q: expected major version 1 or later", version), false
}
return "", true
} | go | func isSupportedAPIVersion(version string) (msg string, ok bool) {
versionParts := strings.Split(version, ".")
if len(versionParts) < 2 {
return fmt.Sprintf("LXD API version %q: expected format <major>.<minor>", version), false
}
major, err := strconv.Atoi(versionParts[0])
if err != nil {
return fmt.Sprintf("LXD API version %q: unexpected major number: %v", version, err), false
}
if major < 1 {
return fmt.Sprintf("LXD API version %q: expected major version 1 or later", version), false
}
return "", true
} | [
"func",
"isSupportedAPIVersion",
"(",
"version",
"string",
")",
"(",
"msg",
"string",
",",
"ok",
"bool",
")",
"{",
"versionParts",
":=",
"strings",
".",
"Split",
"(",
"version",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"versionParts",
")",
"<",
"2",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"version",
")",
",",
"false",
"\n",
"}",
"\n\n",
"major",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"versionParts",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"version",
",",
"err",
")",
",",
"false",
"\n",
"}",
"\n\n",
"if",
"major",
"<",
"1",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"version",
")",
",",
"false",
"\n",
"}",
"\n\n",
"return",
"\"",
"\"",
",",
"true",
"\n",
"}"
] | // isSupportedAPIVersion defines what API versions we support. | [
"isSupportedAPIVersion",
"defines",
"what",
"API",
"versions",
"we",
"support",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/lxd/server.go#L364-L380 |
155,072 | juju/juju | cmd/juju/block/enablecommand.go | NewEnableCommand | func NewEnableCommand() cmd.Command {
return modelcmd.Wrap(&enableCommand{
apiFunc: func(c newAPIRoot) (unblockClientAPI, error) {
return getBlockAPI(c)
},
})
} | go | func NewEnableCommand() cmd.Command {
return modelcmd.Wrap(&enableCommand{
apiFunc: func(c newAPIRoot) (unblockClientAPI, error) {
return getBlockAPI(c)
},
})
} | [
"func",
"NewEnableCommand",
"(",
")",
"cmd",
".",
"Command",
"{",
"return",
"modelcmd",
".",
"Wrap",
"(",
"&",
"enableCommand",
"{",
"apiFunc",
":",
"func",
"(",
"c",
"newAPIRoot",
")",
"(",
"unblockClientAPI",
",",
"error",
")",
"{",
"return",
"getBlockAPI",
"(",
"c",
")",
"\n",
"}",
",",
"}",
")",
"\n",
"}"
] | // NewEnableCommand returns a new command that eanbles previously disabled
// command sets. | [
"NewEnableCommand",
"returns",
"a",
"new",
"command",
"that",
"eanbles",
"previously",
"disabled",
"command",
"sets",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/block/enablecommand.go#L16-L22 |
155,073 | juju/juju | cmd/juju/block/enablecommand.go | Info | func (c *enableCommand) Info() *cmd.Info {
return jujucmd.Info(&cmd.Info{
Name: "enable-command",
Args: "<command set>",
Purpose: "Enable commands that had been previously disabled.",
Doc: enableDoc,
})
} | go | func (c *enableCommand) Info() *cmd.Info {
return jujucmd.Info(&cmd.Info{
Name: "enable-command",
Args: "<command set>",
Purpose: "Enable commands that had been previously disabled.",
Doc: enableDoc,
})
} | [
"func",
"(",
"c",
"*",
"enableCommand",
")",
"Info",
"(",
")",
"*",
"cmd",
".",
"Info",
"{",
"return",
"jujucmd",
".",
"Info",
"(",
"&",
"cmd",
".",
"Info",
"{",
"Name",
":",
"\"",
"\"",
",",
"Args",
":",
"\"",
"\"",
",",
"Purpose",
":",
"\"",
"\"",
",",
"Doc",
":",
"enableDoc",
",",
"}",
")",
"\n",
"}"
] | // Info implementsCommand. | [
"Info",
"implementsCommand",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/juju/block/enablecommand.go#L46-L53 |
155,074 | juju/juju | apiserver/facades/agent/reboot/reboot.go | NewRebootAPI | func NewRebootAPI(st *state.State, resources facade.Resources, auth facade.Authorizer) (*RebootAPI, error) {
if !auth.AuthMachineAgent() {
return nil, common.ErrPerm
}
tag, ok := auth.GetAuthTag().(names.MachineTag)
if !ok {
return nil, errors.Errorf("Expected names.MachineTag, got %T", auth.GetAuthTag())
}
machine, err := st.Machine(tag.Id())
if err != nil {
return nil, errors.Trace(err)
}
canAccess := func() (common.AuthFunc, error) {
return auth.AuthOwner, nil
}
return &RebootAPI{
RebootActionGetter: common.NewRebootActionGetter(st, canAccess),
RebootRequester: common.NewRebootRequester(st, canAccess),
RebootFlagClearer: common.NewRebootFlagClearer(st, canAccess),
st: st,
machine: machine,
resources: resources,
auth: auth,
}, nil
} | go | func NewRebootAPI(st *state.State, resources facade.Resources, auth facade.Authorizer) (*RebootAPI, error) {
if !auth.AuthMachineAgent() {
return nil, common.ErrPerm
}
tag, ok := auth.GetAuthTag().(names.MachineTag)
if !ok {
return nil, errors.Errorf("Expected names.MachineTag, got %T", auth.GetAuthTag())
}
machine, err := st.Machine(tag.Id())
if err != nil {
return nil, errors.Trace(err)
}
canAccess := func() (common.AuthFunc, error) {
return auth.AuthOwner, nil
}
return &RebootAPI{
RebootActionGetter: common.NewRebootActionGetter(st, canAccess),
RebootRequester: common.NewRebootRequester(st, canAccess),
RebootFlagClearer: common.NewRebootFlagClearer(st, canAccess),
st: st,
machine: machine,
resources: resources,
auth: auth,
}, nil
} | [
"func",
"NewRebootAPI",
"(",
"st",
"*",
"state",
".",
"State",
",",
"resources",
"facade",
".",
"Resources",
",",
"auth",
"facade",
".",
"Authorizer",
")",
"(",
"*",
"RebootAPI",
",",
"error",
")",
"{",
"if",
"!",
"auth",
".",
"AuthMachineAgent",
"(",
")",
"{",
"return",
"nil",
",",
"common",
".",
"ErrPerm",
"\n",
"}",
"\n\n",
"tag",
",",
"ok",
":=",
"auth",
".",
"GetAuthTag",
"(",
")",
".",
"(",
"names",
".",
"MachineTag",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"auth",
".",
"GetAuthTag",
"(",
")",
")",
"\n",
"}",
"\n",
"machine",
",",
"err",
":=",
"st",
".",
"Machine",
"(",
"tag",
".",
"Id",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"canAccess",
":=",
"func",
"(",
")",
"(",
"common",
".",
"AuthFunc",
",",
"error",
")",
"{",
"return",
"auth",
".",
"AuthOwner",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"&",
"RebootAPI",
"{",
"RebootActionGetter",
":",
"common",
".",
"NewRebootActionGetter",
"(",
"st",
",",
"canAccess",
")",
",",
"RebootRequester",
":",
"common",
".",
"NewRebootRequester",
"(",
"st",
",",
"canAccess",
")",
",",
"RebootFlagClearer",
":",
"common",
".",
"NewRebootFlagClearer",
"(",
"st",
",",
"canAccess",
")",
",",
"st",
":",
"st",
",",
"machine",
":",
"machine",
",",
"resources",
":",
"resources",
",",
"auth",
":",
"auth",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewRebootAPI creates a new server-side RebootAPI facade. | [
"NewRebootAPI",
"creates",
"a",
"new",
"server",
"-",
"side",
"RebootAPI",
"facade",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/facades/agent/reboot/reboot.go#L34-L61 |
155,075 | juju/juju | worker/machineactions/manifold.go | start | func (config ManifoldConfig) start(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
machineTag, ok := a.CurrentConfig().Tag().(names.MachineTag)
if !ok {
return nil, errors.Errorf("this manifold can only be used inside a machine")
}
machineActionsFacade := config.NewFacade(apiCaller)
return config.NewWorker(WorkerConfig{
Facade: machineActionsFacade,
MachineTag: machineTag,
HandleAction: HandleAction,
})
} | go | func (config ManifoldConfig) start(a agent.Agent, apiCaller base.APICaller) (worker.Worker, error) {
machineTag, ok := a.CurrentConfig().Tag().(names.MachineTag)
if !ok {
return nil, errors.Errorf("this manifold can only be used inside a machine")
}
machineActionsFacade := config.NewFacade(apiCaller)
return config.NewWorker(WorkerConfig{
Facade: machineActionsFacade,
MachineTag: machineTag,
HandleAction: HandleAction,
})
} | [
"func",
"(",
"config",
"ManifoldConfig",
")",
"start",
"(",
"a",
"agent",
".",
"Agent",
",",
"apiCaller",
"base",
".",
"APICaller",
")",
"(",
"worker",
".",
"Worker",
",",
"error",
")",
"{",
"machineTag",
",",
"ok",
":=",
"a",
".",
"CurrentConfig",
"(",
")",
".",
"Tag",
"(",
")",
".",
"(",
"names",
".",
"MachineTag",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"machineActionsFacade",
":=",
"config",
".",
"NewFacade",
"(",
"apiCaller",
")",
"\n",
"return",
"config",
".",
"NewWorker",
"(",
"WorkerConfig",
"{",
"Facade",
":",
"machineActionsFacade",
",",
"MachineTag",
":",
"machineTag",
",",
"HandleAction",
":",
"HandleAction",
",",
"}",
")",
"\n",
"}"
] | // start is used by engine.AgentAPIManifold to create a StartFunc. | [
"start",
"is",
"used",
"by",
"engine",
".",
"AgentAPIManifold",
"to",
"create",
"a",
"StartFunc",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/machineactions/manifold.go#L28-L39 |
155,076 | juju/juju | worker/machineactions/manifold.go | Manifold | func Manifold(config ManifoldConfig) dependency.Manifold {
typedConfig := engine.AgentAPIManifoldConfig{
AgentName: config.AgentName,
APICallerName: config.APICallerName,
}
return engine.AgentAPIManifold(typedConfig, config.start)
} | go | func Manifold(config ManifoldConfig) dependency.Manifold {
typedConfig := engine.AgentAPIManifoldConfig{
AgentName: config.AgentName,
APICallerName: config.APICallerName,
}
return engine.AgentAPIManifold(typedConfig, config.start)
} | [
"func",
"Manifold",
"(",
"config",
"ManifoldConfig",
")",
"dependency",
".",
"Manifold",
"{",
"typedConfig",
":=",
"engine",
".",
"AgentAPIManifoldConfig",
"{",
"AgentName",
":",
"config",
".",
"AgentName",
",",
"APICallerName",
":",
"config",
".",
"APICallerName",
",",
"}",
"\n",
"return",
"engine",
".",
"AgentAPIManifold",
"(",
"typedConfig",
",",
"config",
".",
"start",
")",
"\n",
"}"
] | // Manifold returns a dependency.Manifold as configured. | [
"Manifold",
"returns",
"a",
"dependency",
".",
"Manifold",
"as",
"configured",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/worker/machineactions/manifold.go#L42-L48 |
155,077 | juju/juju | state/database.go | Apply | func Apply(db Database, change Change) error {
db, closer := db.Copy()
defer closer()
buildTxn := func(int) ([]txn.Op, error) {
ops, err := change.Prepare(db)
if errors.Cause(err) == ErrChangeComplete {
return nil, jujutxn.ErrNoOperations
}
if err != nil {
return nil, errors.Trace(err)
}
return ops, nil
}
runner, closer := db.TransactionRunner()
defer closer()
if err := runner.Run(buildTxn); err != nil {
return errors.Trace(err)
}
return nil
} | go | func Apply(db Database, change Change) error {
db, closer := db.Copy()
defer closer()
buildTxn := func(int) ([]txn.Op, error) {
ops, err := change.Prepare(db)
if errors.Cause(err) == ErrChangeComplete {
return nil, jujutxn.ErrNoOperations
}
if err != nil {
return nil, errors.Trace(err)
}
return ops, nil
}
runner, closer := db.TransactionRunner()
defer closer()
if err := runner.Run(buildTxn); err != nil {
return errors.Trace(err)
}
return nil
} | [
"func",
"Apply",
"(",
"db",
"Database",
",",
"change",
"Change",
")",
"error",
"{",
"db",
",",
"closer",
":=",
"db",
".",
"Copy",
"(",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n\n",
"buildTxn",
":=",
"func",
"(",
"int",
")",
"(",
"[",
"]",
"txn",
".",
"Op",
",",
"error",
")",
"{",
"ops",
",",
"err",
":=",
"change",
".",
"Prepare",
"(",
"db",
")",
"\n",
"if",
"errors",
".",
"Cause",
"(",
"err",
")",
"==",
"ErrChangeComplete",
"{",
"return",
"nil",
",",
"jujutxn",
".",
"ErrNoOperations",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"ops",
",",
"nil",
"\n",
"}",
"\n\n",
"runner",
",",
"closer",
":=",
"db",
".",
"TransactionRunner",
"(",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n",
"if",
"err",
":=",
"runner",
".",
"Run",
"(",
"buildTxn",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Apply runs the supplied Change against the supplied Database. If it
// returns no error, the change succeeded. | [
"Apply",
"runs",
"the",
"supplied",
"Change",
"against",
"the",
"supplied",
"Database",
".",
"If",
"it",
"returns",
"no",
"error",
"the",
"change",
"succeeded",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L122-L143 |
155,078 | juju/juju | state/database.go | Create | func (schema CollectionSchema) Create(
db *mgo.Database,
settings *controller.Config,
) error {
for name, info := range schema {
rawCollection := db.C(name)
if spec := info.explicitCreate; spec != nil {
// We allow the max txn log collection size to be overridden by the user.
if name == txnLogC && settings != nil {
maxSize := settings.MaxTxnLogSizeMB()
if maxSize > 0 {
logger.Infof("overriding max txn log collection size: %dM", maxSize)
spec.MaxBytes = maxSize * 1024 * 1024
}
}
if err := createCollection(rawCollection, spec); err != nil {
return mongo.MaybeUnauthorizedf(err, "cannot create collection %q", name)
}
} else {
// With server-side transactions, we need to create all the collections
// outside of a transaction (we don't want to create the collection
// as a side-effect.)
if err := createCollection(rawCollection, &mgo.CollectionInfo{}); err != nil {
return mongo.MaybeUnauthorizedf(err, "cannot create collection %q", name)
}
}
for _, index := range info.indexes {
if err := rawCollection.EnsureIndex(index); err != nil {
return mongo.MaybeUnauthorizedf(err, "cannot create index")
}
}
}
return nil
} | go | func (schema CollectionSchema) Create(
db *mgo.Database,
settings *controller.Config,
) error {
for name, info := range schema {
rawCollection := db.C(name)
if spec := info.explicitCreate; spec != nil {
// We allow the max txn log collection size to be overridden by the user.
if name == txnLogC && settings != nil {
maxSize := settings.MaxTxnLogSizeMB()
if maxSize > 0 {
logger.Infof("overriding max txn log collection size: %dM", maxSize)
spec.MaxBytes = maxSize * 1024 * 1024
}
}
if err := createCollection(rawCollection, spec); err != nil {
return mongo.MaybeUnauthorizedf(err, "cannot create collection %q", name)
}
} else {
// With server-side transactions, we need to create all the collections
// outside of a transaction (we don't want to create the collection
// as a side-effect.)
if err := createCollection(rawCollection, &mgo.CollectionInfo{}); err != nil {
return mongo.MaybeUnauthorizedf(err, "cannot create collection %q", name)
}
}
for _, index := range info.indexes {
if err := rawCollection.EnsureIndex(index); err != nil {
return mongo.MaybeUnauthorizedf(err, "cannot create index")
}
}
}
return nil
} | [
"func",
"(",
"schema",
"CollectionSchema",
")",
"Create",
"(",
"db",
"*",
"mgo",
".",
"Database",
",",
"settings",
"*",
"controller",
".",
"Config",
",",
")",
"error",
"{",
"for",
"name",
",",
"info",
":=",
"range",
"schema",
"{",
"rawCollection",
":=",
"db",
".",
"C",
"(",
"name",
")",
"\n",
"if",
"spec",
":=",
"info",
".",
"explicitCreate",
";",
"spec",
"!=",
"nil",
"{",
"// We allow the max txn log collection size to be overridden by the user.",
"if",
"name",
"==",
"txnLogC",
"&&",
"settings",
"!=",
"nil",
"{",
"maxSize",
":=",
"settings",
".",
"MaxTxnLogSizeMB",
"(",
")",
"\n",
"if",
"maxSize",
">",
"0",
"{",
"logger",
".",
"Infof",
"(",
"\"",
"\"",
",",
"maxSize",
")",
"\n",
"spec",
".",
"MaxBytes",
"=",
"maxSize",
"*",
"1024",
"*",
"1024",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"createCollection",
"(",
"rawCollection",
",",
"spec",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"mongo",
".",
"MaybeUnauthorizedf",
"(",
"err",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// With server-side transactions, we need to create all the collections",
"// outside of a transaction (we don't want to create the collection",
"// as a side-effect.)",
"if",
"err",
":=",
"createCollection",
"(",
"rawCollection",
",",
"&",
"mgo",
".",
"CollectionInfo",
"{",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"mongo",
".",
"MaybeUnauthorizedf",
"(",
"err",
",",
"\"",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"for",
"_",
",",
"index",
":=",
"range",
"info",
".",
"indexes",
"{",
"if",
"err",
":=",
"rawCollection",
".",
"EnsureIndex",
"(",
"index",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"mongo",
".",
"MaybeUnauthorizedf",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Create causes all recorded collections to be created and indexed as specified | [
"Create",
"causes",
"all",
"recorded",
"collections",
"to",
"be",
"created",
"and",
"indexed",
"as",
"specified"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L184-L217 |
155,079 | juju/juju | state/database.go | createCollection | func createCollection(raw *mgo.Collection, spec *mgo.CollectionInfo) error {
err := raw.Create(spec)
// The lack of error code for this error was reported upstream:
// https://jira.mongodb.org/browse/SERVER-6992
if err == nil || strings.HasSuffix(err.Error(), "already exists") {
return nil
}
return err
} | go | func createCollection(raw *mgo.Collection, spec *mgo.CollectionInfo) error {
err := raw.Create(spec)
// The lack of error code for this error was reported upstream:
// https://jira.mongodb.org/browse/SERVER-6992
if err == nil || strings.HasSuffix(err.Error(), "already exists") {
return nil
}
return err
} | [
"func",
"createCollection",
"(",
"raw",
"*",
"mgo",
".",
"Collection",
",",
"spec",
"*",
"mgo",
".",
"CollectionInfo",
")",
"error",
"{",
"err",
":=",
"raw",
".",
"Create",
"(",
"spec",
")",
"\n",
"// The lack of error code for this error was reported upstream:",
"// https://jira.mongodb.org/browse/SERVER-6992",
"if",
"err",
"==",
"nil",
"||",
"strings",
".",
"HasSuffix",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // createCollection swallows collection-already-exists errors. | [
"createCollection",
"swallows",
"collection",
"-",
"already",
"-",
"exists",
"errors",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L220-L228 |
155,080 | juju/juju | state/database.go | CopyForModel | func (db *database) CopyForModel(modelUUID string) (Database, SessionCloser) {
return db.copySession(modelUUID)
} | go | func (db *database) CopyForModel(modelUUID string) (Database, SessionCloser) {
return db.copySession(modelUUID)
} | [
"func",
"(",
"db",
"*",
"database",
")",
"CopyForModel",
"(",
"modelUUID",
"string",
")",
"(",
"Database",
",",
"SessionCloser",
")",
"{",
"return",
"db",
".",
"copySession",
"(",
"modelUUID",
")",
"\n",
"}"
] | // CopyForModel is part of the Database interface. | [
"CopyForModel",
"is",
"part",
"of",
"the",
"Database",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L287-L289 |
155,081 | juju/juju | state/database.go | GetCollection | func (db *database) GetCollection(name string) (collection mongo.Collection, closer SessionCloser) {
info, found := db.schema[name]
if !found {
logger.Errorf("using unknown collection %q", name)
if featureflag.Enabled(feature.DeveloperMode) {
logger.Errorf("from %s", string(debug.Stack()))
}
}
// Copy session if necessary.
if db.ownSession {
collection = mongo.WrapCollection(db.raw.C(name))
closer = dontCloseAnything
} else {
collection, closer = mongo.CollectionFromName(db.raw, name)
}
// Apply model filtering.
if !info.global {
collection = &modelStateCollection{
WriteCollection: collection.Writeable(),
modelUUID: db.modelUUID,
}
}
// Prevent layer-breaking.
if !info.rawAccess {
// TODO(fwereade): it would be nice to tweak the mongo.Collection
// interface a bit to drop Writeable in this situation, but it's
// not convenient yet.
}
return collection, closer
} | go | func (db *database) GetCollection(name string) (collection mongo.Collection, closer SessionCloser) {
info, found := db.schema[name]
if !found {
logger.Errorf("using unknown collection %q", name)
if featureflag.Enabled(feature.DeveloperMode) {
logger.Errorf("from %s", string(debug.Stack()))
}
}
// Copy session if necessary.
if db.ownSession {
collection = mongo.WrapCollection(db.raw.C(name))
closer = dontCloseAnything
} else {
collection, closer = mongo.CollectionFromName(db.raw, name)
}
// Apply model filtering.
if !info.global {
collection = &modelStateCollection{
WriteCollection: collection.Writeable(),
modelUUID: db.modelUUID,
}
}
// Prevent layer-breaking.
if !info.rawAccess {
// TODO(fwereade): it would be nice to tweak the mongo.Collection
// interface a bit to drop Writeable in this situation, but it's
// not convenient yet.
}
return collection, closer
} | [
"func",
"(",
"db",
"*",
"database",
")",
"GetCollection",
"(",
"name",
"string",
")",
"(",
"collection",
"mongo",
".",
"Collection",
",",
"closer",
"SessionCloser",
")",
"{",
"info",
",",
"found",
":=",
"db",
".",
"schema",
"[",
"name",
"]",
"\n",
"if",
"!",
"found",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"name",
")",
"\n",
"if",
"featureflag",
".",
"Enabled",
"(",
"feature",
".",
"DeveloperMode",
")",
"{",
"logger",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"string",
"(",
"debug",
".",
"Stack",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Copy session if necessary.",
"if",
"db",
".",
"ownSession",
"{",
"collection",
"=",
"mongo",
".",
"WrapCollection",
"(",
"db",
".",
"raw",
".",
"C",
"(",
"name",
")",
")",
"\n",
"closer",
"=",
"dontCloseAnything",
"\n",
"}",
"else",
"{",
"collection",
",",
"closer",
"=",
"mongo",
".",
"CollectionFromName",
"(",
"db",
".",
"raw",
",",
"name",
")",
"\n",
"}",
"\n\n",
"// Apply model filtering.",
"if",
"!",
"info",
".",
"global",
"{",
"collection",
"=",
"&",
"modelStateCollection",
"{",
"WriteCollection",
":",
"collection",
".",
"Writeable",
"(",
")",
",",
"modelUUID",
":",
"db",
".",
"modelUUID",
",",
"}",
"\n",
"}",
"\n\n",
"// Prevent layer-breaking.",
"if",
"!",
"info",
".",
"rawAccess",
"{",
"// TODO(fwereade): it would be nice to tweak the mongo.Collection",
"// interface a bit to drop Writeable in this situation, but it's",
"// not convenient yet.",
"}",
"\n",
"return",
"collection",
",",
"closer",
"\n",
"}"
] | // GetCollection is part of the Database interface. | [
"GetCollection",
"is",
"part",
"of",
"the",
"Database",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L292-L324 |
155,082 | juju/juju | state/database.go | GetCollectionFor | func (db *database) GetCollectionFor(modelUUID, name string) (mongo.Collection, SessionCloser) {
newDb, dbcloser := db.CopyForModel(modelUUID)
collection, closer := newDb.GetCollection(name)
return collection, func() {
closer()
dbcloser()
}
} | go | func (db *database) GetCollectionFor(modelUUID, name string) (mongo.Collection, SessionCloser) {
newDb, dbcloser := db.CopyForModel(modelUUID)
collection, closer := newDb.GetCollection(name)
return collection, func() {
closer()
dbcloser()
}
} | [
"func",
"(",
"db",
"*",
"database",
")",
"GetCollectionFor",
"(",
"modelUUID",
",",
"name",
"string",
")",
"(",
"mongo",
".",
"Collection",
",",
"SessionCloser",
")",
"{",
"newDb",
",",
"dbcloser",
":=",
"db",
".",
"CopyForModel",
"(",
"modelUUID",
")",
"\n",
"collection",
",",
"closer",
":=",
"newDb",
".",
"GetCollection",
"(",
"name",
")",
"\n",
"return",
"collection",
",",
"func",
"(",
")",
"{",
"closer",
"(",
")",
"\n",
"dbcloser",
"(",
")",
"\n",
"}",
"\n",
"}"
] | // GetCollectionFor is part of the Database interface. | [
"GetCollectionFor",
"is",
"part",
"of",
"the",
"Database",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L327-L334 |
155,083 | juju/juju | state/database.go | GetRawCollection | func (db *database) GetRawCollection(name string) (*mgo.Collection, SessionCloser) {
collection, closer := db.GetCollection(name)
return collection.Writeable().Underlying(), closer
} | go | func (db *database) GetRawCollection(name string) (*mgo.Collection, SessionCloser) {
collection, closer := db.GetCollection(name)
return collection.Writeable().Underlying(), closer
} | [
"func",
"(",
"db",
"*",
"database",
")",
"GetRawCollection",
"(",
"name",
"string",
")",
"(",
"*",
"mgo",
".",
"Collection",
",",
"SessionCloser",
")",
"{",
"collection",
",",
"closer",
":=",
"db",
".",
"GetCollection",
"(",
"name",
")",
"\n",
"return",
"collection",
".",
"Writeable",
"(",
")",
".",
"Underlying",
"(",
")",
",",
"closer",
"\n",
"}"
] | // GetRawCollection is part of the Database interface. | [
"GetRawCollection",
"is",
"part",
"of",
"the",
"Database",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L337-L340 |
155,084 | juju/juju | state/database.go | TransactionRunner | func (db *database) TransactionRunner() (runner jujutxn.Runner, closer SessionCloser) {
runner = db.runner
closer = dontCloseAnything
if runner == nil {
raw := db.raw
if !db.ownSession {
session := raw.Session.Copy()
raw = raw.With(session)
closer = session.Close
}
observer := func(t jujutxn.Transaction) {
txnLogger.Tracef("ran transaction in %.3fs (retries: %d) %# v\nerr: %v",
t.Duration.Seconds(), t.Attempt, pretty.Formatter(t.Ops), t.Error)
}
if db.runTransactionObserver != nil {
observer = func(t jujutxn.Transaction) {
txnLogger.Tracef("ran transaction in %.3fs (retries: %d) %# v\nerr: %v",
t.Duration.Seconds(), t.Attempt, pretty.Formatter(t.Ops), t.Error)
db.runTransactionObserver(
db.raw.Name, db.modelUUID,
t.Ops, t.Error,
)
}
}
params := jujutxn.RunnerParams{
Database: raw,
RunTransactionObserver: observer,
Clock: db.clock,
ServerSideTransactions: db.serverSideTransactions,
}
runner = jujutxn.NewRunner(params)
}
return &multiModelRunner{
rawRunner: runner,
modelUUID: db.modelUUID,
schema: db.schema,
}, closer
} | go | func (db *database) TransactionRunner() (runner jujutxn.Runner, closer SessionCloser) {
runner = db.runner
closer = dontCloseAnything
if runner == nil {
raw := db.raw
if !db.ownSession {
session := raw.Session.Copy()
raw = raw.With(session)
closer = session.Close
}
observer := func(t jujutxn.Transaction) {
txnLogger.Tracef("ran transaction in %.3fs (retries: %d) %# v\nerr: %v",
t.Duration.Seconds(), t.Attempt, pretty.Formatter(t.Ops), t.Error)
}
if db.runTransactionObserver != nil {
observer = func(t jujutxn.Transaction) {
txnLogger.Tracef("ran transaction in %.3fs (retries: %d) %# v\nerr: %v",
t.Duration.Seconds(), t.Attempt, pretty.Formatter(t.Ops), t.Error)
db.runTransactionObserver(
db.raw.Name, db.modelUUID,
t.Ops, t.Error,
)
}
}
params := jujutxn.RunnerParams{
Database: raw,
RunTransactionObserver: observer,
Clock: db.clock,
ServerSideTransactions: db.serverSideTransactions,
}
runner = jujutxn.NewRunner(params)
}
return &multiModelRunner{
rawRunner: runner,
modelUUID: db.modelUUID,
schema: db.schema,
}, closer
} | [
"func",
"(",
"db",
"*",
"database",
")",
"TransactionRunner",
"(",
")",
"(",
"runner",
"jujutxn",
".",
"Runner",
",",
"closer",
"SessionCloser",
")",
"{",
"runner",
"=",
"db",
".",
"runner",
"\n",
"closer",
"=",
"dontCloseAnything",
"\n",
"if",
"runner",
"==",
"nil",
"{",
"raw",
":=",
"db",
".",
"raw",
"\n",
"if",
"!",
"db",
".",
"ownSession",
"{",
"session",
":=",
"raw",
".",
"Session",
".",
"Copy",
"(",
")",
"\n",
"raw",
"=",
"raw",
".",
"With",
"(",
"session",
")",
"\n",
"closer",
"=",
"session",
".",
"Close",
"\n",
"}",
"\n",
"observer",
":=",
"func",
"(",
"t",
"jujutxn",
".",
"Transaction",
")",
"{",
"txnLogger",
".",
"Tracef",
"(",
"\"",
"\\n",
"\"",
",",
"t",
".",
"Duration",
".",
"Seconds",
"(",
")",
",",
"t",
".",
"Attempt",
",",
"pretty",
".",
"Formatter",
"(",
"t",
".",
"Ops",
")",
",",
"t",
".",
"Error",
")",
"\n",
"}",
"\n",
"if",
"db",
".",
"runTransactionObserver",
"!=",
"nil",
"{",
"observer",
"=",
"func",
"(",
"t",
"jujutxn",
".",
"Transaction",
")",
"{",
"txnLogger",
".",
"Tracef",
"(",
"\"",
"\\n",
"\"",
",",
"t",
".",
"Duration",
".",
"Seconds",
"(",
")",
",",
"t",
".",
"Attempt",
",",
"pretty",
".",
"Formatter",
"(",
"t",
".",
"Ops",
")",
",",
"t",
".",
"Error",
")",
"\n",
"db",
".",
"runTransactionObserver",
"(",
"db",
".",
"raw",
".",
"Name",
",",
"db",
".",
"modelUUID",
",",
"t",
".",
"Ops",
",",
"t",
".",
"Error",
",",
")",
"\n",
"}",
"\n",
"}",
"\n",
"params",
":=",
"jujutxn",
".",
"RunnerParams",
"{",
"Database",
":",
"raw",
",",
"RunTransactionObserver",
":",
"observer",
",",
"Clock",
":",
"db",
".",
"clock",
",",
"ServerSideTransactions",
":",
"db",
".",
"serverSideTransactions",
",",
"}",
"\n",
"runner",
"=",
"jujutxn",
".",
"NewRunner",
"(",
"params",
")",
"\n",
"}",
"\n",
"return",
"&",
"multiModelRunner",
"{",
"rawRunner",
":",
"runner",
",",
"modelUUID",
":",
"db",
".",
"modelUUID",
",",
"schema",
":",
"db",
".",
"schema",
",",
"}",
",",
"closer",
"\n",
"}"
] | // TransactionRunner is part of the Database interface. | [
"TransactionRunner",
"is",
"part",
"of",
"the",
"Database",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L343-L380 |
155,085 | juju/juju | state/database.go | RunTransaction | func (db *database) RunTransaction(ops []txn.Op) error {
runner, closer := db.TransactionRunner()
defer closer()
return runner.RunTransaction(&jujutxn.Transaction{Ops: ops})
} | go | func (db *database) RunTransaction(ops []txn.Op) error {
runner, closer := db.TransactionRunner()
defer closer()
return runner.RunTransaction(&jujutxn.Transaction{Ops: ops})
} | [
"func",
"(",
"db",
"*",
"database",
")",
"RunTransaction",
"(",
"ops",
"[",
"]",
"txn",
".",
"Op",
")",
"error",
"{",
"runner",
",",
"closer",
":=",
"db",
".",
"TransactionRunner",
"(",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n",
"return",
"runner",
".",
"RunTransaction",
"(",
"&",
"jujutxn",
".",
"Transaction",
"{",
"Ops",
":",
"ops",
"}",
")",
"\n",
"}"
] | // RunTransaction is part of the Database interface. | [
"RunTransaction",
"is",
"part",
"of",
"the",
"Database",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L383-L387 |
155,086 | juju/juju | state/database.go | RunTransactionFor | func (db *database) RunTransactionFor(modelUUID string, ops []txn.Op) error {
newDB, dbcloser := db.CopyForModel(modelUUID)
defer dbcloser()
runner, closer := newDB.TransactionRunner()
defer closer()
return runner.RunTransaction(&jujutxn.Transaction{Ops: ops})
} | go | func (db *database) RunTransactionFor(modelUUID string, ops []txn.Op) error {
newDB, dbcloser := db.CopyForModel(modelUUID)
defer dbcloser()
runner, closer := newDB.TransactionRunner()
defer closer()
return runner.RunTransaction(&jujutxn.Transaction{Ops: ops})
} | [
"func",
"(",
"db",
"*",
"database",
")",
"RunTransactionFor",
"(",
"modelUUID",
"string",
",",
"ops",
"[",
"]",
"txn",
".",
"Op",
")",
"error",
"{",
"newDB",
",",
"dbcloser",
":=",
"db",
".",
"CopyForModel",
"(",
"modelUUID",
")",
"\n",
"defer",
"dbcloser",
"(",
")",
"\n",
"runner",
",",
"closer",
":=",
"newDB",
".",
"TransactionRunner",
"(",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n",
"return",
"runner",
".",
"RunTransaction",
"(",
"&",
"jujutxn",
".",
"Transaction",
"{",
"Ops",
":",
"ops",
"}",
")",
"\n",
"}"
] | // RunTransactionFor is part of the Database interface. | [
"RunTransactionFor",
"is",
"part",
"of",
"the",
"Database",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L390-L396 |
155,087 | juju/juju | state/database.go | RunRawTransaction | func (db *database) RunRawTransaction(ops []txn.Op) error {
runner, closer := db.TransactionRunner()
defer closer()
if multiRunner, ok := runner.(*multiModelRunner); ok {
runner = multiRunner.rawRunner
}
return runner.RunTransaction(&jujutxn.Transaction{Ops: ops})
} | go | func (db *database) RunRawTransaction(ops []txn.Op) error {
runner, closer := db.TransactionRunner()
defer closer()
if multiRunner, ok := runner.(*multiModelRunner); ok {
runner = multiRunner.rawRunner
}
return runner.RunTransaction(&jujutxn.Transaction{Ops: ops})
} | [
"func",
"(",
"db",
"*",
"database",
")",
"RunRawTransaction",
"(",
"ops",
"[",
"]",
"txn",
".",
"Op",
")",
"error",
"{",
"runner",
",",
"closer",
":=",
"db",
".",
"TransactionRunner",
"(",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n",
"if",
"multiRunner",
",",
"ok",
":=",
"runner",
".",
"(",
"*",
"multiModelRunner",
")",
";",
"ok",
"{",
"runner",
"=",
"multiRunner",
".",
"rawRunner",
"\n",
"}",
"\n",
"return",
"runner",
".",
"RunTransaction",
"(",
"&",
"jujutxn",
".",
"Transaction",
"{",
"Ops",
":",
"ops",
"}",
")",
"\n",
"}"
] | // RunRawTransaction is part of the Database interface. | [
"RunRawTransaction",
"is",
"part",
"of",
"the",
"Database",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L399-L406 |
155,088 | juju/juju | state/database.go | Run | func (db *database) Run(transactions jujutxn.TransactionSource) error {
runner, closer := db.TransactionRunner()
defer closer()
return runner.Run(transactions)
} | go | func (db *database) Run(transactions jujutxn.TransactionSource) error {
runner, closer := db.TransactionRunner()
defer closer()
return runner.Run(transactions)
} | [
"func",
"(",
"db",
"*",
"database",
")",
"Run",
"(",
"transactions",
"jujutxn",
".",
"TransactionSource",
")",
"error",
"{",
"runner",
",",
"closer",
":=",
"db",
".",
"TransactionRunner",
"(",
")",
"\n",
"defer",
"closer",
"(",
")",
"\n",
"return",
"runner",
".",
"Run",
"(",
"transactions",
")",
"\n",
"}"
] | // Run is part of the Database interface. | [
"Run",
"is",
"part",
"of",
"the",
"Database",
"interface",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/state/database.go#L409-L413 |
155,089 | juju/juju | apiserver/common/leadership.go | Machine | func (s leadershipPinningBackend) Machine(name string) (LeadershipMachine, error) {
m, err := s.State.Machine(name)
if err != nil {
return nil, err
}
return leadershipMachine{m}, nil
} | go | func (s leadershipPinningBackend) Machine(name string) (LeadershipMachine, error) {
m, err := s.State.Machine(name)
if err != nil {
return nil, err
}
return leadershipMachine{m}, nil
} | [
"func",
"(",
"s",
"leadershipPinningBackend",
")",
"Machine",
"(",
"name",
"string",
")",
"(",
"LeadershipMachine",
",",
"error",
")",
"{",
"m",
",",
"err",
":=",
"s",
".",
"State",
".",
"Machine",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"leadershipMachine",
"{",
"m",
"}",
",",
"nil",
"\n",
"}"
] | // Machine wraps state.Machine to return an implementation
// of the LeadershipMachine indirection. | [
"Machine",
"wraps",
"state",
".",
"Machine",
"to",
"return",
"an",
"implementation",
"of",
"the",
"LeadershipMachine",
"indirection",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/leadership.go#L39-L45 |
155,090 | juju/juju | apiserver/common/leadership.go | NewLeadershipPinningFacade | func NewLeadershipPinningFacade(ctx facade.Context) (LeadershipPinningAPI, error) {
st := ctx.State()
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
pinner, err := ctx.LeadershipPinner(model.UUID())
if err != nil {
return nil, errors.Trace(err)
}
return NewLeadershipPinningAPI(leadershipPinningBackend{st}, model.ModelTag(), pinner, ctx.Auth())
} | go | func NewLeadershipPinningFacade(ctx facade.Context) (LeadershipPinningAPI, error) {
st := ctx.State()
model, err := st.Model()
if err != nil {
return nil, errors.Trace(err)
}
pinner, err := ctx.LeadershipPinner(model.UUID())
if err != nil {
return nil, errors.Trace(err)
}
return NewLeadershipPinningAPI(leadershipPinningBackend{st}, model.ModelTag(), pinner, ctx.Auth())
} | [
"func",
"NewLeadershipPinningFacade",
"(",
"ctx",
"facade",
".",
"Context",
")",
"(",
"LeadershipPinningAPI",
",",
"error",
")",
"{",
"st",
":=",
"ctx",
".",
"State",
"(",
")",
"\n",
"model",
",",
"err",
":=",
"st",
".",
"Model",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"pinner",
",",
"err",
":=",
"ctx",
".",
"LeadershipPinner",
"(",
"model",
".",
"UUID",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"NewLeadershipPinningAPI",
"(",
"leadershipPinningBackend",
"{",
"st",
"}",
",",
"model",
".",
"ModelTag",
"(",
")",
",",
"pinner",
",",
"ctx",
".",
"Auth",
"(",
")",
")",
"\n",
"}"
] | // NewLeadershipPinningFacade creates and returns a new leadership API.
// This signature is suitable for facade registration. | [
"NewLeadershipPinningFacade",
"creates",
"and",
"returns",
"a",
"new",
"leadership",
"API",
".",
"This",
"signature",
"is",
"suitable",
"for",
"facade",
"registration",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/leadership.go#L56-L67 |
155,091 | juju/juju | apiserver/common/leadership.go | NewLeadershipPinningAPI | func NewLeadershipPinningAPI(
st LeadershipPinningBackend, modelTag names.ModelTag, pinner leadership.Pinner, authorizer facade.Authorizer,
) (LeadershipPinningAPI, error) {
return &leadershipPinningAPI{
st: st,
modelTag: modelTag,
pinner: pinner,
authorizer: authorizer,
}, nil
} | go | func NewLeadershipPinningAPI(
st LeadershipPinningBackend, modelTag names.ModelTag, pinner leadership.Pinner, authorizer facade.Authorizer,
) (LeadershipPinningAPI, error) {
return &leadershipPinningAPI{
st: st,
modelTag: modelTag,
pinner: pinner,
authorizer: authorizer,
}, nil
} | [
"func",
"NewLeadershipPinningAPI",
"(",
"st",
"LeadershipPinningBackend",
",",
"modelTag",
"names",
".",
"ModelTag",
",",
"pinner",
"leadership",
".",
"Pinner",
",",
"authorizer",
"facade",
".",
"Authorizer",
",",
")",
"(",
"LeadershipPinningAPI",
",",
"error",
")",
"{",
"return",
"&",
"leadershipPinningAPI",
"{",
"st",
":",
"st",
",",
"modelTag",
":",
"modelTag",
",",
"pinner",
":",
"pinner",
",",
"authorizer",
":",
"authorizer",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewLeadershipPinningAPI creates and returns a new leadership API from the
// input tag, Pinner implementation and facade Authorizer. | [
"NewLeadershipPinningAPI",
"creates",
"and",
"returns",
"a",
"new",
"leadership",
"API",
"from",
"the",
"input",
"tag",
"Pinner",
"implementation",
"and",
"facade",
"Authorizer",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/leadership.go#L71-L80 |
155,092 | juju/juju | apiserver/common/leadership.go | PinnedLeadership | func (a *leadershipPinningAPI) PinnedLeadership() (params.PinnedLeadershipResult, error) {
result := params.PinnedLeadershipResult{}
canAccess, err := a.authorizer.HasPermission(permission.ReadAccess, a.modelTag)
if err != nil {
return result, errors.Trace(err)
}
if !canAccess {
return result, ErrPerm
}
result.Result = a.pinner.PinnedLeadership()
return result, nil
} | go | func (a *leadershipPinningAPI) PinnedLeadership() (params.PinnedLeadershipResult, error) {
result := params.PinnedLeadershipResult{}
canAccess, err := a.authorizer.HasPermission(permission.ReadAccess, a.modelTag)
if err != nil {
return result, errors.Trace(err)
}
if !canAccess {
return result, ErrPerm
}
result.Result = a.pinner.PinnedLeadership()
return result, nil
} | [
"func",
"(",
"a",
"*",
"leadershipPinningAPI",
")",
"PinnedLeadership",
"(",
")",
"(",
"params",
".",
"PinnedLeadershipResult",
",",
"error",
")",
"{",
"result",
":=",
"params",
".",
"PinnedLeadershipResult",
"{",
"}",
"\n\n",
"canAccess",
",",
"err",
":=",
"a",
".",
"authorizer",
".",
"HasPermission",
"(",
"permission",
".",
"ReadAccess",
",",
"a",
".",
"modelTag",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"result",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"!",
"canAccess",
"{",
"return",
"result",
",",
"ErrPerm",
"\n",
"}",
"\n\n",
"result",
".",
"Result",
"=",
"a",
".",
"pinner",
".",
"PinnedLeadership",
"(",
")",
"\n",
"return",
"result",
",",
"nil",
"\n",
"}"
] | // PinnedLeadership returns all pinned applications and the entities that
// require their pinned behaviour, for leadership in the current model. | [
"PinnedLeadership",
"returns",
"all",
"pinned",
"applications",
"and",
"the",
"entities",
"that",
"require",
"their",
"pinned",
"behaviour",
"for",
"leadership",
"in",
"the",
"current",
"model",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/leadership.go#L91-L104 |
155,093 | juju/juju | apiserver/common/leadership.go | UnpinMachineApplications | func (a *leadershipPinningAPI) UnpinMachineApplications() (params.PinApplicationsResults, error) {
if !a.authorizer.AuthMachineAgent() {
return params.PinApplicationsResults{}, ErrPerm
}
return a.pinMachineAppsOps(a.pinner.UnpinLeadership)
} | go | func (a *leadershipPinningAPI) UnpinMachineApplications() (params.PinApplicationsResults, error) {
if !a.authorizer.AuthMachineAgent() {
return params.PinApplicationsResults{}, ErrPerm
}
return a.pinMachineAppsOps(a.pinner.UnpinLeadership)
} | [
"func",
"(",
"a",
"*",
"leadershipPinningAPI",
")",
"UnpinMachineApplications",
"(",
")",
"(",
"params",
".",
"PinApplicationsResults",
",",
"error",
")",
"{",
"if",
"!",
"a",
".",
"authorizer",
".",
"AuthMachineAgent",
"(",
")",
"{",
"return",
"params",
".",
"PinApplicationsResults",
"{",
"}",
",",
"ErrPerm",
"\n",
"}",
"\n",
"return",
"a",
".",
"pinMachineAppsOps",
"(",
"a",
".",
"pinner",
".",
"UnpinLeadership",
")",
"\n",
"}"
] | // UnpinMachineApplications unpins leadership for applications represented by
// units running on the auth'd machine. | [
"UnpinMachineApplications",
"unpins",
"leadership",
"for",
"applications",
"represented",
"by",
"units",
"running",
"on",
"the",
"auth",
"d",
"machine",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/apiserver/common/leadership.go#L121-L126 |
155,094 | juju/juju | cmd/modelcmd/clientstore.go | QualifiedModelName | func (s QualifyingClientStore) QualifiedModelName(controllerName, modelName string) (string, error) {
if modelName == "" {
return "", nil
}
if !jujuclient.IsQualifiedModelName(modelName) {
details, err := s.ClientStore.AccountDetails(controllerName)
if err != nil {
return "", errors.Annotate(err, "getting account details for qualifying model name")
}
owner := names.NewUserTag(details.User)
modelName = jujuclient.JoinOwnerModelName(owner, modelName)
} else {
unqualifiedModelName, owner, err := jujuclient.SplitModelName(modelName)
if err != nil {
return "", errors.Trace(err)
}
owner = names.NewUserTag(owner.Id())
modelName = jujuclient.JoinOwnerModelName(owner, unqualifiedModelName)
}
return modelName, nil
} | go | func (s QualifyingClientStore) QualifiedModelName(controllerName, modelName string) (string, error) {
if modelName == "" {
return "", nil
}
if !jujuclient.IsQualifiedModelName(modelName) {
details, err := s.ClientStore.AccountDetails(controllerName)
if err != nil {
return "", errors.Annotate(err, "getting account details for qualifying model name")
}
owner := names.NewUserTag(details.User)
modelName = jujuclient.JoinOwnerModelName(owner, modelName)
} else {
unqualifiedModelName, owner, err := jujuclient.SplitModelName(modelName)
if err != nil {
return "", errors.Trace(err)
}
owner = names.NewUserTag(owner.Id())
modelName = jujuclient.JoinOwnerModelName(owner, unqualifiedModelName)
}
return modelName, nil
} | [
"func",
"(",
"s",
"QualifyingClientStore",
")",
"QualifiedModelName",
"(",
"controllerName",
",",
"modelName",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"modelName",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"nil",
"\n",
"}",
"\n",
"if",
"!",
"jujuclient",
".",
"IsQualifiedModelName",
"(",
"modelName",
")",
"{",
"details",
",",
"err",
":=",
"s",
".",
"ClientStore",
".",
"AccountDetails",
"(",
"controllerName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Annotate",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"owner",
":=",
"names",
".",
"NewUserTag",
"(",
"details",
".",
"User",
")",
"\n",
"modelName",
"=",
"jujuclient",
".",
"JoinOwnerModelName",
"(",
"owner",
",",
"modelName",
")",
"\n",
"}",
"else",
"{",
"unqualifiedModelName",
",",
"owner",
",",
"err",
":=",
"jujuclient",
".",
"SplitModelName",
"(",
"modelName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"owner",
"=",
"names",
".",
"NewUserTag",
"(",
"owner",
".",
"Id",
"(",
")",
")",
"\n",
"modelName",
"=",
"jujuclient",
".",
"JoinOwnerModelName",
"(",
"owner",
",",
"unqualifiedModelName",
")",
"\n",
"}",
"\n",
"return",
"modelName",
",",
"nil",
"\n",
"}"
] | // QualifiedModelName returns a Qualified model name, given either
// an unqualified or qualified model name. If the input is a
// fully qualified name, it is returned untouched; otherwise it is
// return qualified with the logged-in user name. | [
"QualifiedModelName",
"returns",
"a",
"Qualified",
"model",
"name",
"given",
"either",
"an",
"unqualified",
"or",
"qualified",
"model",
"name",
".",
"If",
"the",
"input",
"is",
"a",
"fully",
"qualified",
"name",
"it",
"is",
"returned",
"untouched",
";",
"otherwise",
"it",
"is",
"return",
"qualified",
"with",
"the",
"logged",
"-",
"in",
"user",
"name",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/cmd/modelcmd/clientstore.go#L25-L45 |
155,095 | juju/juju | provider/gce/google/ruleset.go | portStrings | func (pp protocolPorts) portStrings(protocol string) []string {
var result []string
ports := pp[protocol]
for _, pr := range ports {
portStr := fmt.Sprintf("%d", pr.FromPort)
if pr.FromPort != pr.ToPort {
portStr = fmt.Sprintf("%s-%d", portStr, pr.ToPort)
}
result = append(result, portStr)
}
return result
} | go | func (pp protocolPorts) portStrings(protocol string) []string {
var result []string
ports := pp[protocol]
for _, pr := range ports {
portStr := fmt.Sprintf("%d", pr.FromPort)
if pr.FromPort != pr.ToPort {
portStr = fmt.Sprintf("%s-%d", portStr, pr.ToPort)
}
result = append(result, portStr)
}
return result
} | [
"func",
"(",
"pp",
"protocolPorts",
")",
"portStrings",
"(",
"protocol",
"string",
")",
"[",
"]",
"string",
"{",
"var",
"result",
"[",
"]",
"string",
"\n",
"ports",
":=",
"pp",
"[",
"protocol",
"]",
"\n",
"for",
"_",
",",
"pr",
":=",
"range",
"ports",
"{",
"portStr",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"pr",
".",
"FromPort",
")",
"\n",
"if",
"pr",
".",
"FromPort",
"!=",
"pr",
".",
"ToPort",
"{",
"portStr",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"portStr",
",",
"pr",
".",
"ToPort",
")",
"\n",
"}",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"portStr",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // portStrings returns a list of stringified ports in the set
// for the given protocol. | [
"portStrings",
"returns",
"a",
"list",
"of",
"stringified",
"ports",
"in",
"the",
"set",
"for",
"the",
"given",
"protocol",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/ruleset.go#L219-L230 |
155,096 | juju/juju | provider/gce/google/ruleset.go | union | func (pp protocolPorts) union(other protocolPorts) protocolPorts {
result := make(protocolPorts)
for protocol, ports := range pp {
result[protocol] = ports
}
for protocol, otherPorts := range other {
resultPorts := result[protocol]
for _, other := range otherPorts {
found := false
for _, myRange := range resultPorts {
if myRange == other {
found = true
break
}
}
if !found {
resultPorts = append(resultPorts, other)
}
}
result[protocol] = resultPorts
}
return result
} | go | func (pp protocolPorts) union(other protocolPorts) protocolPorts {
result := make(protocolPorts)
for protocol, ports := range pp {
result[protocol] = ports
}
for protocol, otherPorts := range other {
resultPorts := result[protocol]
for _, other := range otherPorts {
found := false
for _, myRange := range resultPorts {
if myRange == other {
found = true
break
}
}
if !found {
resultPorts = append(resultPorts, other)
}
}
result[protocol] = resultPorts
}
return result
} | [
"func",
"(",
"pp",
"protocolPorts",
")",
"union",
"(",
"other",
"protocolPorts",
")",
"protocolPorts",
"{",
"result",
":=",
"make",
"(",
"protocolPorts",
")",
"\n",
"for",
"protocol",
",",
"ports",
":=",
"range",
"pp",
"{",
"result",
"[",
"protocol",
"]",
"=",
"ports",
"\n",
"}",
"\n",
"for",
"protocol",
",",
"otherPorts",
":=",
"range",
"other",
"{",
"resultPorts",
":=",
"result",
"[",
"protocol",
"]",
"\n",
"for",
"_",
",",
"other",
":=",
"range",
"otherPorts",
"{",
"found",
":=",
"false",
"\n",
"for",
"_",
",",
"myRange",
":=",
"range",
"resultPorts",
"{",
"if",
"myRange",
"==",
"other",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"resultPorts",
"=",
"append",
"(",
"resultPorts",
",",
"other",
")",
"\n",
"}",
"\n",
"}",
"\n",
"result",
"[",
"protocol",
"]",
"=",
"resultPorts",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // union returns a new protocolPorts combining the port
// ranges from both. | [
"union",
"returns",
"a",
"new",
"protocolPorts",
"combining",
"the",
"port",
"ranges",
"from",
"both",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/ruleset.go#L234-L256 |
155,097 | juju/juju | provider/gce/google/ruleset.go | remove | func (pp protocolPorts) remove(other protocolPorts) protocolPorts {
result := make(protocolPorts)
for protocol, otherPorts := range other {
myRange, ok := pp[protocol]
if !ok {
continue
}
var resultRange []corenetwork.PortRange
for _, one := range myRange {
found := false
for _, other := range otherPorts {
if one == other {
found = true
break
}
}
if !found {
resultRange = append(resultRange, one)
}
}
if len(resultRange) > 0 {
result[protocol] = resultRange
}
}
return result
} | go | func (pp protocolPorts) remove(other protocolPorts) protocolPorts {
result := make(protocolPorts)
for protocol, otherPorts := range other {
myRange, ok := pp[protocol]
if !ok {
continue
}
var resultRange []corenetwork.PortRange
for _, one := range myRange {
found := false
for _, other := range otherPorts {
if one == other {
found = true
break
}
}
if !found {
resultRange = append(resultRange, one)
}
}
if len(resultRange) > 0 {
result[protocol] = resultRange
}
}
return result
} | [
"func",
"(",
"pp",
"protocolPorts",
")",
"remove",
"(",
"other",
"protocolPorts",
")",
"protocolPorts",
"{",
"result",
":=",
"make",
"(",
"protocolPorts",
")",
"\n",
"for",
"protocol",
",",
"otherPorts",
":=",
"range",
"other",
"{",
"myRange",
",",
"ok",
":=",
"pp",
"[",
"protocol",
"]",
"\n",
"if",
"!",
"ok",
"{",
"continue",
"\n",
"}",
"\n",
"var",
"resultRange",
"[",
"]",
"corenetwork",
".",
"PortRange",
"\n",
"for",
"_",
",",
"one",
":=",
"range",
"myRange",
"{",
"found",
":=",
"false",
"\n",
"for",
"_",
",",
"other",
":=",
"range",
"otherPorts",
"{",
"if",
"one",
"==",
"other",
"{",
"found",
"=",
"true",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"!",
"found",
"{",
"resultRange",
"=",
"append",
"(",
"resultRange",
",",
"one",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"resultRange",
")",
">",
"0",
"{",
"result",
"[",
"protocol",
"]",
"=",
"resultRange",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // remove returns a new protocolPorts with the port ranges
// in the specified protocolPorts removed. | [
"remove",
"returns",
"a",
"new",
"protocolPorts",
"with",
"the",
"port",
"ranges",
"in",
"the",
"specified",
"protocolPorts",
"removed",
"."
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/gce/google/ruleset.go#L260-L285 |
155,098 | juju/juju | provider/maas/maas2storage.go | Get | func (stor *maas2Storage) Get(name string) (io.ReadCloser, error) {
name = stor.prefixWithPrivateNamespace(name)
file, err := stor.maasController.GetFile(name)
if err != nil {
if gomaasapi.IsNoMatchError(err) {
return nil, errors.Wrap(err, errors.NotFoundf(name))
}
return nil, errors.Trace(err)
}
contents, err := file.ReadAll()
if err != nil {
return nil, errors.Trace(err)
}
return ioutil.NopCloser(bytes.NewReader(contents)), nil
} | go | func (stor *maas2Storage) Get(name string) (io.ReadCloser, error) {
name = stor.prefixWithPrivateNamespace(name)
file, err := stor.maasController.GetFile(name)
if err != nil {
if gomaasapi.IsNoMatchError(err) {
return nil, errors.Wrap(err, errors.NotFoundf(name))
}
return nil, errors.Trace(err)
}
contents, err := file.ReadAll()
if err != nil {
return nil, errors.Trace(err)
}
return ioutil.NopCloser(bytes.NewReader(contents)), nil
} | [
"func",
"(",
"stor",
"*",
"maas2Storage",
")",
"Get",
"(",
"name",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"name",
"=",
"stor",
".",
"prefixWithPrivateNamespace",
"(",
"name",
")",
"\n",
"file",
",",
"err",
":=",
"stor",
".",
"maasController",
".",
"GetFile",
"(",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"gomaasapi",
".",
"IsNoMatchError",
"(",
"err",
")",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"errors",
".",
"NotFoundf",
"(",
"name",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"contents",
",",
"err",
":=",
"file",
".",
"ReadAll",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"ioutil",
".",
"NopCloser",
"(",
"bytes",
".",
"NewReader",
"(",
"contents",
")",
")",
",",
"nil",
"\n",
"}"
] | // Get implements storage.StorageReader | [
"Get",
"implements",
"storage",
".",
"StorageReader"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/maas/maas2storage.go#L35-L49 |
155,099 | juju/juju | provider/maas/maas2storage.go | List | func (stor *maas2Storage) List(prefix string) ([]string, error) {
prefix = stor.prefixWithPrivateNamespace(prefix)
files, err := stor.maasController.Files(prefix)
if err != nil {
return nil, errors.Trace(err)
}
privatePrefix := stor.prefixWithPrivateNamespace("")
names := make([]string, len(files))
for i, file := range files {
// Remove the private namespacing.
names[i] = strings.TrimPrefix(file.Filename(), privatePrefix)
}
sort.Strings(names)
return names, nil
} | go | func (stor *maas2Storage) List(prefix string) ([]string, error) {
prefix = stor.prefixWithPrivateNamespace(prefix)
files, err := stor.maasController.Files(prefix)
if err != nil {
return nil, errors.Trace(err)
}
privatePrefix := stor.prefixWithPrivateNamespace("")
names := make([]string, len(files))
for i, file := range files {
// Remove the private namespacing.
names[i] = strings.TrimPrefix(file.Filename(), privatePrefix)
}
sort.Strings(names)
return names, nil
} | [
"func",
"(",
"stor",
"*",
"maas2Storage",
")",
"List",
"(",
"prefix",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"prefix",
"=",
"stor",
".",
"prefixWithPrivateNamespace",
"(",
"prefix",
")",
"\n",
"files",
",",
"err",
":=",
"stor",
".",
"maasController",
".",
"Files",
"(",
"prefix",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Trace",
"(",
"err",
")",
"\n",
"}",
"\n",
"privatePrefix",
":=",
"stor",
".",
"prefixWithPrivateNamespace",
"(",
"\"",
"\"",
")",
"\n",
"names",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"files",
")",
")",
"\n",
"for",
"i",
",",
"file",
":=",
"range",
"files",
"{",
"// Remove the private namespacing.",
"names",
"[",
"i",
"]",
"=",
"strings",
".",
"TrimPrefix",
"(",
"file",
".",
"Filename",
"(",
")",
",",
"privatePrefix",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"names",
")",
"\n",
"return",
"names",
",",
"nil",
"\n",
"}"
] | // List implements storage.StorageReader | [
"List",
"implements",
"storage",
".",
"StorageReader"
] | ba728eedb1e44937c7bdc59f374b06400d0c7133 | https://github.com/juju/juju/blob/ba728eedb1e44937c7bdc59f374b06400d0c7133/provider/maas/maas2storage.go#L52-L66 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.